ZF-6269: Errors decorator on Zend_Form
Description
Adding an Errors decorator to Zend_Form throws an error if any element of the form is not valid and no errors are set for the form.
<?php
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
$oEmail = new Zend_Form_Element_Text('email');
$oEmail
->addValidator('EmailAddress', true)
->clearDecorators()
->addDecorator('ViewHelper')
->addDecorator('Errors')
->setRequired(true);
$oForm = new Zend_Form();
$oForm
->addElement($oEmail)
->clearDecorators()
->addDecorator('FormElements')
->addDecorator('Errors', array('placement' => Zend_Form_Decorator_Abstract::PREPEND))
->addDecorator('Form');
$oForm->isValid(array('email' => 'foo'));
$oForm->addErrors(array('Sign up failed')); // Without this throws an error
echo $oForm->render(new Zend_View());
Comments
Posted by Steve Hollis (stevehollis) on 2009-11-19T12:57:34.000+0000
The 'Errors' decorator (Zend_Form_Decorator_Errors) is designed for use with form elements whilst the 'FormErrors' (Zend_Form_Decorator_FormErrors) decorator is designed for use with whole forms.
You can use one or other or both, but the right decorator must be applied to the right object type.
See docs: http://framework.zend.com/manual/en/…