可能重复:
Zend form validation
这是我的文件格式:
$file = new Zend_Form_Element_File('file', array(
'required' => true,
'MaxFileSize' => 4194304,
'validators' => array(
array('Count', false, 1),
array('Size', false, 4194304),
array('Extension', false, 'gif,jpg,png'),
array('ImageSize', false, array('minwidth' => 40,
'minheight' => 40,
'maxwidth' => 90,
'maxheight' => 90)))));
如何删除验证者消息?
答案 0 :(得分:1)
每个验证器的最后一个参数可以是一个数组。可以传递的参数之一是'messages',它是表示每个错误的验证器特定常量数组,以及错误消息的字符串。您可以通过查看验证器类(例如Zend / Validate / File / ImageSize.php)来获取错误代码列表。在您的情况下,这些将是:
$file = new Zend_Form_Element_File('file', array(
'required' => false, //we will add this as a custom validator so we can over-ride the error message
'MaxFileSize' => 4194304,
'validators' => array(
array('NotEmpty', true, array('messages' => array('isEmpty' => "Your error message here")))
array('Count', false, array(count => 1, 'messages' => array('fileCountTooFew' => "Too few files, minimum '%min%' are expected but '%count%' are given", 'fileCountTooMany' => "Too many files, maximum '%max%' are allowed but '%count%' are given"))),
array('Size', false, array('size' => 4194304, 'messages'=> array('fileSizeTooBig' => "", 'fileSizeTooSmall' => "", 'fileSizeNotFound' => ""))),
array('Extension', false, array('extension' => 'gif,jpg,png', 'messages' => array('fileExtensionFalse' => "", 'fileExtensionNotFound' => ""))),
array('ImageSize', false, array('minwidth' => 40,
'minheight' => 40,
'maxwidth' => 90,
'maxheight' => 90,
'messages' => array(
'fileImageSizeWidthTooBig' => "Maximum allowed width for image '%value%' should be '%maxwidth%' but '%width%' detected",
'fileImageSizeWidthTooSmall' => "Minimum expected width for image '%value%' should be '%minwidth%' but '%width%' detected",
'fileImageSizeHeightTooBig' => "Maximum allowed height for image '%value%' should be '%maxheight%' but '%height%' detected",
'fileImageSizeHeightTooSmall' => "Minimum expected height for image '%value%' should be '%minheight%' but '%height%' detected",
'fileImageSizeNotDetected' => "The size of image '%value%' could not be detected",
'fileImageSizeNotReadable' => "File '%value%' can not be read",
)
)
)
)
)
);