ZF-6269: Errors decorator on Zend_Form


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.

require_once 'Zend/Loader.php';

$oEmail = new Zend_Form_Element_Text('email');
    ->addValidator('EmailAddress', true)

$oForm = new Zend_Form();
    ->addDecorator('Errors', array('placement' => Zend_Form_Decorator_Abstract::PREPEND))

$oForm->isValid(array('email' => 'foo'));
$oForm->addErrors(array('Sign up failed')); // Without this throws an error

echo $oForm->render(new Zend_View());


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:…