Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
weierophinney opened this issue Dec 31, 2019 · 1 comment
Assignees
Labels
Bug Something isn't working
Milestone

Comments

@weierophinney
Copy link
Member

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.


Originally posted by @dabroderick at zendframework/zend-validator#230

@gsteel
Copy link
Member

gsteel commented Jun 25, 2024

Closed via #286 - error messages are now array<string, string>

@gsteel gsteel closed this as completed Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants