ZF-4030: Warning on form validation
Description
For each invalid field Zend_Form generates a warning:
Warning: htmlspecialchars() expects parameter 1 to be string, array given in /Library/WebServer/Library/Zend/View/Abstract.php on line 804
I've encountered this with both Select fields and normal Text fields, but other elements might be affected as well. A valid field does not generate this warning. The error messages do appear next to the elements.
Select code:
$fieldElement1 = new Zend_Form_Element_Select('field1');
$fieldElement1->setRequired(true)
->setAllowEmpty(false)
->setMultiOptions(array('foo' => 'FOO', 'bar' => 'BAR'));
Textfield code:
$queryElement1 = new Zend_Form_Element_Text('query1');
$queryElement1->setRequired(true)
->setAllowEmpty(false);
Edit:
The call to Zend_View_Abstract's escape() method originates from Zend_View_Helper_FormErrors line 75. A var_dump() on line 74 gives these results:
array 'isEmpty' => string 'Value is empty, but a non-empty value is required' (length=49)
array 'isEmpty' => string 'Value is empty, but a non-empty value is required' (length=49)
array 'field1' => array 'isEmpty' => string 'Value is empty, but a non-empty value is required' (length=49) 'query1' => array 'isEmpty' => string 'Value is empty, but a non-empty value is required' (length=49)
Edit2: It appears it's caused by adding the Errors decorator manually with $this->addDecorator('Errors');
Comments
Posted by Matthew Weier O'Phinney (matthew) on 2008-08-23T20:57:03.000+0000
I'm actually unsure exactly what the issue is. I've tried creating the elements you specify, passing invalid values to isValid(), and rendering, but with no errors. I've even tried specifying adding the Errors decorator manually -- I simply cannot reproduce any sort of warning.
I'm going to mark the issue as "cannot reproduce". Feel free to re-open if you can provide the following, succinctly: * Reproduce case * Expected result (this can even be "no warnings") * Actual result (this could be "warnings generated" -- please make sure you paste in the warnings)
Posted by Jurrien Stutterheim (norm2782) on 2008-08-24T03:53:48.000+0000
Both of these code snippets reproduce the bug:
Output:
FOOBAR'baz' was not found in the haystackValue is empty, but a non-empty value is requiredPosted by Matthew Weier O'Phinney (matthew) on 2008-08-24T14:31:46.000+0000
The 'Errors' decorator is currently not intended for use at the form level, only with individual elements. I'm going to change this to a feature request, as we probably need a 'FormErrors' decorator.
Posted by Matthew Weier O'Phinney (matthew) on 2008-11-07T08:14:08.000+0000
FormErrors decorator added in r12369 to trunk; will release with 1.7.0
Posted by Wil Sinclair (wil) on 2008-11-13T14:10:09.000+0000
Changing issues in preparation for the 1.7.0 release.
Posted by ved prakash bishnoi (vpgodara) on 2010-01-20T03:31:52.000+0000
Use this for remove haystack error
$fieldElement1 = new Zend_Form_Element_Select('field1'); $fieldElement1->setRequired(true) ->setRegisterInArrayValidator(false); </code