I need to display form-level errors in my forms (errors that do not belong to one field, but to the whole form submission), with this code:
$form->addError($message);
For this to work, I need to add the relevant decorator to my form:
$form->addDecorator('Errors');
Fairly easy. The problem is that applying a new decorator causes all default decorators to be removed, thus forcing me to re-apply all of them:
$form->addDecorator('Errors')
->addDecorator('FormElements')
->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form'))
->addDecorator('Form');
This is some redundant code I have in most of my forms. Is it possible to have the Errors
decorator part of the default decorators, by applying some setting?
I could obviously create an abstract Form
class to inherit from, but I'm wondering if I'm missing a simpler or more elegant solution.
You can override the loadDefaultDecorators method to create a form class that support errors like:
Errors decorator should be the first one to render. I think more elegant solution would require Zend_Form refactoring.