I’ve set a validator for the email so it can’t be empty.
This is the markup of the usual form that zend_form generates:
<dt id="email-label"><label class="required" for="email">Email</label></dt>
<dd id="email-element">
<input type="text" value="" id="email" name="email">
</dd>
When validation fails, zend_form adds a new ul class="errors" inside the dd
<dt id="email-label"><label class="required" for="email">Email</label></dt>
<dd id="email-element">
<input type="text" value="" id="email" name="email">
<ul class="errors">
<li>Value is required and can't be empty</li>
</ul>
</dd>
How can I change this default behavior slightly so that the entire dt dd gets wrapped in a single p or something that I can add an error class to? My guess is that I need to specify to zend_form how to behave when an element has errors.
You can create your own decorator to do that, something simple like this::
Now you can just register this decorator for the element:
You can also register the prefix path for all elements at the same time by using
$form->addElementPrefixPath()instead.If you want to add this decorator (and the prefix path) automatically for all elements, I suggest you extend each element the Zend’s corresponding one (eg. make
My_Form_Element_Textthat extendsZend_Form_Element_Text), and then add the prefix path in the init function, and overrideloadDefaultDecorators()method to add theElementWrapperat the end of the decorator chain. For example, this is howloadDefaultDecorators()looks forZend_Form_Element_Text:You’d just add a
->addDecorator('ElementWrapper')at the end of the chain. So to show a concrete example ofMy_Form_Element_Text: