Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify password field in zend form?

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?

like image 786
Andrew Avatar asked Oct 27 '09 03:10

Andrew


1 Answers

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.

like image 76
Jason Gilmore Avatar answered Sep 20 '22 19:09

Jason Gilmore