Password Confirmation in zend framework
Posted
by Behrang
on Stack Overflow
See other posts from Stack Overflow
or by Behrang
Published on 2010-03-05T21:11:21Z
Indexed on
2010/03/17
21:01 UTC
Read the original article
Hit count: 300
I add this class to library/My/Validate/PasswordConfirmation.php
<?php
require_once 'Zend/Validate/Abstract.php';
class My_Validate_PasswordConfirmation extends Zend_Validate_Abstract
{
const NOT_MATCH = 'notMatch';
protected $_messageTemplates = array(
self::NOT_MATCH => 'Password confirmation does not match'
);
public function isValid($value, $context = null)
{
$value = (string) $value;
$this->_setValue($value);
if (is_array($context)) {
if (isset($context['password'])
&& ($value == $context['password']))
{
return true;
}
} elseif (is_string($context) && ($value == $context)) {
return true;
}
$this->_error(self::NOT_MATCH);
return false;
}
}
?>
then I create two field in my form like this :
$userPassword = $this->createElement('password', 'user_password');
$userPassword->setLabel('Password: ');
$userPassword->setRequired('true');
$this->addElement($userPassword);
//create the form elements user_password repeat
$userPasswordRepeat = $this->createElement('password', 'password_confirm');
$userPasswordRepeat->setLabel('Password repeat: ');
$userPasswordRepeat->setRequired('true');
$userPasswordRepeat->addPrefixPath('My_Validate','My/Validate','validate');
$userPasswordRepeat->addValidator('PasswordConfirmation');
$this->addElement($userPasswordRepeat)
everything is good but when i submit form always I get the 'Password confirmation does not match' message ? What's Wrong in my code
© Stack Overflow or respective owner