所以我使用的是Zend,我有一个带有Zend_Form_Element_File和三个验证器的Zend表单:
1. setrequired
2.扩展
3.尺寸
1. setrequired
2.扩展
3.尺寸
$this->browse = new Zend_Form_Element_File('Browse'); $this->browse->setrequired(false)->removeDecorator('errors')->removeDecorator('label') ->addValidator('Extension',true,'pdf')->addValidator('Size',false,2000000);
我想设置自定义错误消息的原因是因为我有一个自定义装饰器,当表单与isValid()无效时我抓住所有错误并将其显示在表单的顶部.我在表单中捕获错误的方法是getErrors().
我也尝试过:http://www.mail-archive.com/fw-general@lists.zend.com/msg25779.html
通过做:
$validator = new Zend_Validate_File_Upload(); $validator->setMessages(array('fileUploadErrorNoFile' => 'Upload an image!''));
和做
$this->browse->addValidator($validator);
有帮助吗?
这是我用来设置自定义验证器消息的方式.
原文链接:https://www.f2er.com/php/133696.html$file = new Zend_Form_Element_File('file'); $file->setLabel('File Label') ->setMaxFileSize('512000') ->addValidator('Count',1) ->addValidator('Size',512000) ->addValidator('Extension','jpg,jpeg,png,gif'); $file->getValidator('Count')->setMessage('You can upload only one file'); $file->getValidator('Size')->setMessage('Your file size cannot upload file size limit of 512 kb'); $file->getValidator('Extension')->setMessage('Invalid file extension,only valid image with file format jpg,png and gif are allowed.');
http://framework.zend.com/manual/en/zend.validate.messages.html