If you define your validator as an external variable, use setMessage () :
$validator = new Zend_Validate_Alnum(); $validator->setMessage('My custom error message for given validation rule', Zend_Validate_Alnum::INVALID); $formElement->addValidator($validator);
As you see in the example above, the validator for the form is no different from other types of Zend_Validate_ * instances.
Setting up verification messages includes searching for API Documents and determining the message constant for this verification error (as in the case of Zend_Validate_Alnum :: INVALID). Of course, if your IDE provides good context autofill, just entering a validation class might be enough - since in most cases the message constants are really clear.
Another way is to use the Zend_Form magic methods and just pass the βmessageβ as a parameter to your validator:
$formElement->addValidator(array( 'alnum', false, array('messages' => array( Zend_Validate_Alnum::INVALID => 'my message' )) ));
This will internally call the setMessages () method defined in Zend_Validate_Abstract, and essentially it's just a reduction or time delay defined for Zend_Form's.
NB: there is a highlighted section in the ZF manual for verification messages.
source share