Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

ZF3 Using Explode with InArray validator as child breaks validation messages format #230

Open
dabroderick opened this issue May 18, 2018 · 1 comment

Comments

@dabroderick
Copy link

dabroderick commented May 18, 2018

I am using the following array notation in my form creation for a single select element:

'validators' => [
[
	'name' => 'Explode',
	'options' => [
		'validator' => [
			'name'=>'InArray', 
			'options'=>[
				'haystack'=>[1,2],
				'message'=> 'Invalid status'
			]
		]
	]
],
]

When I submit an invalid option, I get this from $form->getMessages():

  array (size=3)
  'status' => 
    array (size=2)
      'notInArray' => string 'The input was not found in the haystack' (length=39)
      0 => 
        array (size=1)
          'notInArray' => string 'Invalid status' (length=14)

Without the Explode layer in the validators,

[
     'name'=>'InArray', 
     'options'=>[
          'haystack'=>[1,2],
          'message'=>'Invalid status'
     ]
],

$form->getMessages() reports this when invalid:

array (size=3)
  'status' => 
    array (size=1)
      'notInArray' => string 'Invalid status' (length=14)

Since Explode does not acknowledge a message option and when I set disable_inarray_validator to true I still get:

  'status' => 
    array (size=2)
      'notInArray' => string 'The input was not found in the haystack' (length=39)
      0 => 
        array (size=1)
          'notInArray' => string 'Invalid status' (length=14)

What I am expecting to get is:

'status' => 
    array (size=1)
      'notInArray' => 
        array (size=1)
          0 => string 'Invalid status' (length=14)

From what I can tell, Explode is a utility to help process validators rather than being an actual validator. But in using it, it breaks validation messages so my standard code for processing form validation messages does not work.

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-validator; a new issue has been opened at laminas/laminas-validator#5.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants