脚本宝典收集整理的这篇文章主要介绍了php – 如何设置自定义错误消息zend表单元素文件?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$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);
有帮助吗?
$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
以上是脚本宝典为你收集整理的php – 如何设置自定义错误消息zend表单元素文件?全部内容,希望文章能够帮你解决php – 如何设置自定义错误消息zend表单元素文件?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。