There is no way to override ALL error messages
How can I override all error messages for a form element?
-
13-12-2021 - |
Question
I can use the following method to override all the error messages of a zend form element.
$name->setRequired( TRUE )
->setAttrib( 'id', 'fullname' )
->addErrorMessage( 'Please provide your name' );
However, I cannot replicate this when I am creating a form element using the factory pattern.
The 'errorMessage' key does nothing.
$this->addElement('text', 'city', array(
'placeholder' => 'City*',
'required' => true,
'filters' => array('StringTrim', 'StripTags'),
'errorMessage' => 'TEST',
'validators' => array(
array('StringLength', false,
array(3, 50,
/*'messages' => array(
Zend_Validate_StringLength::TOO_SHORT => 'too short'
)*/
)
)
),
'decorators' => array('ViewHelper','Errors'),
));
I can override each Zend error message individually(see commented out code) but that is a very tedious process.
Is there a way to override all error messages when creating ZF form element using the factory pattern?
Solution 2
OTHER TIPS
I haven't tried it, but I think you can do:
'errorMessages' => array('TEST'),
Notice that errorMessages
is plural, and you're passing in a one-element array instead of a string.
If you want to change error message then you define that at the time of validators define like..
'validators' => array(
'NotEmpty',
true,
array( 'messages' => array( 'isEmpty' => "Please provide your name.") )
when this field is blank then error message will be "Please provide your name.".