Zend talk.By default,using the FormErrors decorator the generated list of errors has the following markup:
<ul class="form-errors>
<li>
<b>[element label or name]</b>
<ul>
<li>[error message]</li>
<li>[error message]</li>
</ul>
</li>
</ul>
Question: How can I use the following structure instead?
<span class='myErrors'>
•[error message]</br>
</span>
Update: I tried with:
array('FormErrors', array(
'markupListStart' => "<span class='myErrors'>",
'markupListEnd' => '</span>',
'markupListItemStart' => '',
'markupListItemEnd' => '</br>',
'ignoreSubForms'=> false,
'showCustomFormErrors' => true,
'onlyCustomFormErrors'=> false,
'markupElementLabelEnd' => '',
'markupElementLabelStart' => ''
));
But I still have unwanted tags and labels.This is the source code:
<span class='myErrors'>
[element label or name]
<ul class="errors">
<li>
[error message]
</li>
</ul>
</br>
</span>
You need two things: A decorator and a view helper. By default
Zend Form
uses the'Errors'
decorator, which uses theFormErrors
view helper. You need to override this to achieve what you need. Take this simple example to illustrate this:As you can see, the second decorator I'm using for my
$name
form element, is an new object ofMy_Form_Error_Decorator
class, which looks something like this:This is in fact almost the same decorator as the default
'Errors'
decorator, the only line I change is this$errors = $viewhelp->myErrorViewer($errors, $this->getOptions());
Here I'm telling the decorator to use theMy_Form_Error_View_Helper
view helper, which in turn look something like this:Again I borrow most of this function from the original
FormErrors
View Helper. This is by no means the solution you should implement, but hopefully this sets you on the right path on how you can use decorators and view helper to customize the output of your form. I recommend the following two reads about Decorators and View Helpers (They are a huge topic by themselves)Decorators View Helpers
The simples thing would be to create own decorator. You can take Zend decorator and modify the code. But I would recommend to put the messages in
element instead of for the sake of semantics, span is after all an in-line element and you want to make multiple lines.
If you do not want to create new decorator you can try pass an array with data like in the Zend FormErrors options
Create similar array with appropriate tags.