I have created a form to add a user to a database and make user available for login.
Now I have two password fields (the second is for validation of the first). How can I add a validator for this kind of validation to zend_form?
This is my code for the two password fields:
$password = new Zend_Form_Element_Password('password', array(
'validators'=> array(
'Alnum',
array('StringLength', array(6,20))
),
'filters' => array('StringTrim'),
'label' => 'Wachtwoord:'
));
$password->addFilter(new Ivo_Filters_Sha1Filter());
$password2 = new Zend_Form_Element_Password('password', array(
'validators'=> array(
'Alnum',
array('StringLength', array(6,20))
),
'filters' => array('StringTrim'),
'required' => true,
'label' => 'Wachtwoord:'
));
$password2->addFilter(new Ivo_Filters_Sha1Filter());
The current version of Zend_Validate has this built in - while there are plenty of other answers, it seems that all require passing a value to
Zend_Validate_Identical
. While that may have been needed at one point, you can now pass the name of another element.From the
Zend_Validate
section of the reference guide:You can access all form fields from validator, also you can use constructor to pass additional arguments
to call this validator
When I was looking for the same, I found this very well working generic Validator for Identical Fields. I don't find it now so I just post the code...
here is how i done this :)
create first pass input then crate second pass input and add Identical validator with data from previous password input.