So I am using Zend and I have a Zend form with a Zend_Form_Element_File and three validators:
1. setRequired
2. Extension
3. Size
$this->browse = new Zend_Form_Element_File('Browse');
$this->browse->setRequired(false)->removeDecorator('errors')->removeDecorator('label')
->addValidator('Extension', true, 'pdf')->addValidator('Size', false, 2000000);
I want to set custom error messages for these validators but do not know how.
The reason I want to set a custom error message is because I have a custom decorator with which I grab all errors when the form is not valid with isValid() and display them at the top of the form. The method for which I am grabbing errors in the form is getErrors().
I've also tried: http://www.mail-archive.com/fw-general@lists.zend.com/msg25779.html
by doing:
$validator = new Zend_Validate_File_Upload();
$validator->setMessages(array('fileUploadErrorNoFile' => 'Upload an image!''));
and doing
$this->browse->addValidator($validator);
Any help?
Best Answer
this is how i use to set custom validator message.
here are some of the links that may prove useful to understand custom validator message.
http://framework.zend.com/manual/en/zend.validate.messages.html
Zend Framework Custom Validation Class Error Message
Can't set custom validator messages in Zend_Form