zend 相同验证器将一个元素留空时出现问题
我使用以下代码:
$form->addElement('password', 'elementOne');
$form->addElement('password', 'elementTwo', array(
'validators' => array(
array('identical', false, array('token' => 'elementOne'))
)
));
如果两个文本不同,我会从验证器收到错误,但如果我将第二个文本留空,则验证将不会触发。为什么?
(我不想按要求输入字段,因为用户只有在想要更改密码时才应该填写这些字段,但他也可以将它们留空)
我做错了什么?我应该将验证器放在两个元素上吗?
I'm using the following code:
$form->addElement('password', 'elementOne');
$form->addElement('password', 'elementTwo', array(
'validators' => array(
array('identical', false, array('token' => 'elementOne'))
)
));
If both texts are different I get an error from the validator, but if I leave the second one empty the validation wont fire. why?
(I dont want to put the fields as required because the user should fill them only if he wants to change the password but he could also leave them empty)
What am I doing wrong? should I put the validator on both elements?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题在于AllowEmpty 标志(当不需要元素时,此标志设置为true)。我将其设置为 false,验证器现在按预期触发。
设置允许为空(假)
The problem was the AllowEmpty flag (when the element is not required this flag is set to true). I set it to false and the validator is now firing as expected.
setAllowEmpty(false)