|
Size: | 17505 |
Storage flags: | no_autoload,compress/gzip (22%) |
The FormElementErrors view helper is used to render the validation error messages of an element.
Basic usage:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | use Zend\Form\Form;
use Zend\Form\Element;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Input;
// Create a form
$form = new Form();
$element = new Element\Text('my-text');
$form->add($element);
// Create a input
$input = new Input('my-text');
$input->setRequired(true);
$inputFilter = new InputFilter();
$inputFilter->add($input);
$form->setInputFilter($inputFilter);
// Force a failure
$form->setData(array()); // Empty data
$form->isValid(); // Not valid
// Within your view...
/**
* Example #1: Default options
*/
echo $this->formElementErrors($element);
// <ul><li>Value is required and can't be empty</li></ul>
/**
* Example #2: Add attributes to open format
*/
echo $this->formElementErrors($element, array('class' => 'help-inline'));
// <ul class="help-inline"><li>Value is required and can't be empty</li></ul>
/**
* Example #3: Custom format
*/
echo $this->formElementErrors()
->setMessageOpenFormat('<div class="help-inline">')
->setMessageSeparatorString('</div><div class="help-inline">')
->setMessageCloseString('</div>')
->render($element);
// <div class="help-inline">Value is required and can't be empty</div>
|
The following public methods are in addition to those inherited from Zend\Form\View\Helper\AbstractHelper.
Set the formatted string used to open message representation.
Parameters: | $messageOpenFormat – The formatted string to use to open the messages. Uses '<ul%s><li>' by default. Attributes are inserted here. |
---|
Returns the formatted string used to open message representation.
Return type: | string |
---|
Sets the string used to separate messages.
Parameters: | $messageSeparatorString – The string to use to separate the messages. Uses '</li><li>' by default. |
---|
Returns the string used to separate messages.
Return type: | string |
---|
Sets the string used to close message representation.
Parameters: | $messageCloseString – The string to use to close the messages. Uses '</li></ul>' by default. |
---|
Returns the string used to close message representation.
Return type: | string |
---|
Set the attributes that will go on the message open format.
Parameters: | $attributes – Key value pairs of attributes. |
---|
Returns the attributes that will go on the message open format.
Return type: | array |
---|
Renders validation errors for the provided $element.
Parameters: |
|
---|---|
Return type: | string |
The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.