How to verify password field in zend form?

前端 未结 7 1317
旧巷少年郎
旧巷少年郎 2021-02-04 09:39

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

7条回答
  •  别那么骄傲
    2021-02-04 10:08

    With Zend Framework 1.10 the code needed to validate the equality of two fields using Zend Form and Zend Validate is:

        $form->addElement('PasswordTextBox',
                          'password',
                          array('label'      => 'Password')
                          );
    
        $form->addElement('PasswordTextBox',
                          'password_confirm',
                          array('label'      => 'Confirm password',
                                'validators' => array(array('Identical', false, 'password')),
                                )
                          );
    

    You can notice, in the validators array of the password_confirm element, that the Identical validator is passed as array, the semantics of that array is: i) Validator name, ii) break chain on failure, iii) validator options As you can see, it's possible to pass the field name instead of retrieving the value.

提交回复
热议问题