Zend_Form 要求 =>真错误
我对 Zend_Form 空验证器有问题,即使表单为空,它也会验证并返回 true。例如,如果 username = ' ' 验证器返回 true。
如果字符串为空,表单
$this->addElement('text','username',array(
'label' => 'APP_FORM_USERNAME',
'require' => true,
'validators' => array(
array('validator' => 'StringLength', true, 'options' => array(3, 50)),
array('validator' => 'Alpha', true),
array('validator' => 'NotEmpty', true, 'options' => Zend_Validate_NotEmpty::ALL)
),
'filters' => array(
'StringTrim'
))
);
如何返回 false? 谢谢。
I have a problem with Zend_Form empty validator, it validates and return true even if the form is empty. For exemple if username = ' ' the validator returns true.
The Form
$this->addElement('text','username',array(
'label' => 'APP_FORM_USERNAME',
'require' => true,
'validators' => array(
array('validator' => 'StringLength', true, 'options' => array(3, 50)),
array('validator' => 'Alpha', true),
array('validator' => 'NotEmpty', true, 'options' => Zend_Validate_NotEmpty::ALL)
),
'filters' => array(
'StringTrim'
))
);
How can i return false if is a string is empty?
Thx.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还是要回答,尽管我认为自从几个月前你提出这个问题以来你可能已经找到了答案。
setRequired(true)
实际上与notEmpty
验证器具有相同的效果。它将在验证器堆栈顶部添加一个 notEmpty 验证器。你的错误只是一个简单的语法错误:require应该是required。
I'm going to answer even though I think you probably have found an answer since you ased this question a couple of months ago already.
setRequired(true)
has actually the same effect than thenotEmpty
validator. It will add anotEmpty
validator on top of the validators stack.Your mistake is just a simple syntax error: require should be required.