为 zf2 实现密码验证器
问题描述:
编写验证两个输入的密码验证器的好方法是什么(必须是 eqeal)以及如何将其集成到 zf2 表单中.
What is a good approach to write a password validator that validates two inputs (must be eqeal) and how would you integrate that into a zf2 form.
答
有一个Identical"验证器可以检查两个字段是否相等,它可以在表单构造函数中以如下方式使用:
There is an "Identical" validator that check two fields to be equal, it can be used in the following way in form constructor:
$this->add(array(
'name' => 'password', // add first password field
/* ... other params ... */
));
$this->add(array(
'name' => 'passwordCheck', // add second password field
/* ... other params ... */
'validators' => array(
array(
'name' => 'Identical',
'options' => array(
'token' => 'password', // name of first password field
),
),
),
));