Implementing a password validator for zf2

2019-04-09 10:45发布

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.

1条回答
Fickle 薄情
2楼-- · 2019-04-09 11:47

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
            ),
        ),
    ),
));
查看更多
登录 后发表回答