How to verify password field in zend form?

前端 未结 7 1313
旧巷少年郎
旧巷少年郎 2021-02-04 09:39

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

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 10:02

    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_confirm'])
                && ($value == $context['password_confirm']))
            {
                return true;
            }
        } elseif (is_string($context) && ($value == $context)) {
            return true;
        }
    
        $this->_error(self::NOT_MATCH);
        return false;
    }
    }
    

    http://framework.zend.com/manual/en/zend.form.elements.html

提交回复
热议问题