If I have a form element that has multiple validators attached to it (3 in this example), how would I use addErrorMessage
to create custom error messages when each unique validator fails. Is there a way to add a custom message for each validator?
$element = new Zend_Form_Element_Text()...
$element->....
->addValidator(...)
->addValidator(...)
->addValidator(...)
->addErrorMessage()
Add your message along with the validator as below. Example:
addErrorMessage('Your Custom Message'); It is also easiest way to print the custom message.
The addErrorMessage is defined inside libraray/zend/Form/Elements.php
Hope it helps!!
Typically it's done per validator error message, not per validator...
But I often prefer to override all of an element's errors to a single
or, if I need it per validator, this works...
should override all a validator's errors to a single message. I could not find this documented anywhere, but it works for me. Because of this, it may not work for all versions?
To me, the error messaging handling is a bit messy unless you want to override every possible error message, but hopefully one of these solutions works for you.
Cheers
Add your message like this
->addValidator( 'Alpha', true, array( 'messages' => array( 'notAlpha' => "Please enter alphabetic character only in Product name.
") ));
Add validator message according to your error string