A while back i needed a password confirmation field for my users. I looked and found this neat little snippet. I cant remember who created it originally so i cant give credits to the person but its quite easy to use. Just add this to your library and create a new validator object like this.
This would be in your form where you want to have password confirmation.
Pingback: Zend Framework in Action » Christian Kirkegaard: Password confirmation using Zend Form and Validators
Nice!
It would be more general purpose if you could configure the validator with the names of the two password fields. Maybe passed in the constructor?
Thanks for a great snippet. ;-)
My friend Jeremy Kendall (http://www.jeremykendall.net) and I worked on this.
Pingback: Zend Framework News » Blog Archive » Passwortvalidierung mit Zend_Form und Zend_Validator
Original script is from this tutorial by Andrei Nikolov: http://zfsite.andreinikolov.com/2008/05/part-4-zendform-captcha-password-confirmation-date-selector-field-zendtranslate/
Pingback: Linkpool Nummer 5 | PHP Gangsta - Der PHP Blog
Im getting the Not match always, even if I put same passwords in both of the textbox..
MyValidatePasswordConfirmation
const NOT_MATCH = ‘notMatch’;
protected $_messageTemplates = array(self::NOT_MATCH => 'Passwords do
not match.’);
public function isValid($value, $context = null){
$value = (string) $value;
$this->_setValue($value);
if (is_array($context)) {
if (isset($context['confirmation']) && ($value ==$context['confirmation'])) {
return true;
}
} elseif (is_string($context) && ($value == $context)) {
return true;
}
$this->_error(self::NOT_MATCH);
return false;
}
And my Form
$password = new ZendFormElement_Password(‘passwd’,array(
‘required’ => true,
‘label’ => ‘Password’,
‘size’ => 11
));
$confirmation = new Zend_Form_Element_Password('confirmation',array(
'required' => true,
'label' => 'Re-Password',
'size' => 11
));
//$confirmation->addValidator('PasswordConfirmation',array('passwd'), true);
Could you help me please…
the validator doesnt take any arguments. Just parse the validator to your elements
Nice way, but there is an already existing validator called ZendValidateIdentical
ZendValidateIdentical supports also the comparison of form elements. This can be done by using the element’s name as token. See the following example:
$form->addElement('password', 'elementOne');
$form->addElement('password', 'elementTwo', array(
'validators' => array(
array('identical', false, array('token' => 'elementOne'))
)
));
”
thanks, just saved me some time!! IOU one O Red Hug :)