如何验证zend表单中的密码字段? [英] How to verify password field in zend form?
问题描述
在我的表单中,我试图验证用户两次填写的值是否相同(以确保他们没有出错).我认为这就是 Zend_Validate_Identical
的用途,但我不太确定如何使用它.这是我到目前为止所得到的:
$this->addElement('password', 'password', array('标签' =>'密码:','必需' =>真的,'验证器' =>大批('相同' =>数组(我在这里放什么?))));$this->addElement('密码', '验证密码', 数组('标签' =>'验证密码:','必需' =>真的,'验证器' =>大批('相同' =>数组(我在这里放什么?))));
两个元素都需要它吗?我在数组中放了什么?
就其价值而言,在 1.10.5 版本中添加了对模型中两个相同表单字段进行比较的支持.我写了一个关于这个问题的简短教程,你可以通过下面的链接访问,但最重要的是 Zend_Validate_Identical 验证器已被重构为接受表单字段名称作为输入.例如,要比较表单字段pswd 和confirm_pswd 的值,您需要将验证器附加到confirm_pswd,如下所示:
$confirmPswd->addValidator('Identical', false, array('token' => 'pswd'));
就像一个魅力.
请参阅使用 Zend 框架验证相同的密码以获得更完整的示例.>
In my form, I'm trying to verify that the user fills in the same value both times (to make sure they didn't make a mistake). I think that's what Zend_Validate_Identical
is for, but I'm not quite sure how to use it. Here's what I've got so far:
$this->addElement('password', 'password', array(
'label' => 'Password:',
'required' => true,
'validators' => array(
'Identical' => array(What do I put here?)
)
));
$this->addElement('password', 'verifypassword', array(
'label' => 'Verify Password:',
'required' => true,
'validators' => array(
'Identical' => array(What do I put here?)
)
));
Do I need it on both elements? What do I put in the array?
For what its worth, support for comparing two identical form fields within a model was added to the 1.10.5 release. I wrote up a short tutorial on the matter, which you can access via the below link, but the bottom line is that the Zend_Validate_Identical validator has been refactored to accept a form field name as input. For instance, to compare the values of form fields pswd and confirm_pswd, you'll attach the validator to confirm_pswd like so:
$confirmPswd->addValidator('Identical', false, array('token' => 'pswd'));
Works like a charm.
See Validating Identical Passwords with the Zend Framework for a more complete example.
这篇关于如何验证zend表单中的密码字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!