小编3eh*_*ang的帖子

zend框架中的密码确认

我将这个类添加到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;
    }
}
?>
Run Code Online (Sandbox Code Playgroud)

然后我在我的表单中创建两个字段,如下所示:

       $userPassword = $this->createElement('password', 'user_password');
    $userPassword->setLabel('Password: ');
    $userPassword->setRequired('true');
    $this->addElement($userPassword);

    //create the form elements …
Run Code Online (Sandbox Code Playgroud)

passwords zend-framework zend-form

5
推荐指数
3
解决办法
1万
查看次数

标签 统计

passwords ×1

zend-form ×1

zend-framework ×1