How to add required error message to my input in Zend Framework 1.11?
php, zend-form, zend-form-element, zend-framework, zend-validate
Solution
In the end, i got this to work:
$this->addElement('text', 'age', array(
'label'=>'Age',
'maxlength'=>2,
'class'=>'age',
'required'=>true,
'filters'=>array('StringTrim'),
'validators'=>array(
array(
'validator'=>'NotEmpty',
'options'=>array(
'messages'=>'Please enter your age.'
),
'breakChainOnFailure'=>true
),
array(
'validator'=>'Int',
'options'=>array(
'messages'=>'Age must be a number.'
),
'breakChainOnFailure'=>true
),
array(
'validator'=>'between',
'options'=>array(
'min'=>8,
'max'=>10,
'messages'=>array(
Zend_Validate_Between::NOT_BETWEEN => 'This is for %min% to %max% years old.'
)
)
),
),
'decorators'=>array(
'ViewHelper',
'Errors',
array(array('control'=>'HtmlTag'), array('tag'=>'div', 'class'=>'fieldcontrol')),
array('Label', array('tag'=>'div', 'class'=>'age')),
array(array('row'=>'HtmlTag'), array('tag' => 'div', 'class'=>'row')),
),
));
Problem
I have the following code snippets in my forms/video.php. But i do not know where to add the validation message for required. ``` $this->addElement('text','name', array( 'label'=>'Name', 'maxlength'=>20, 'class'=>'name', 'required'=>true, 'filters'=>array('StringTrim'), 'decorators'=>array( 'ViewHelper', 'Errors', array(array('control'=>'HtmlTag'), array('tag'=>'div', 'class'=>'fieldcontrol')), array('Label', array('tag'=>'div', 'class'=>'name')), array(array('row'=>'HtmlTag'), array('tag' => 'div', 'class'=>'row')), ) )); ``` Instead of "Value is required and can't be empty", I would like to set it to something else like "Please enter your name".