2012-08-14 39 views
0

在Zend Form中使用更改密碼時,我想檢查舊密碼和新密碼。兩者不應該是一樣的。Zend Form中有任何選項可以檢查兩者。以zend-form的驗證

在此先感謝。

+0

當您在控制器或型號代碼中處理表單時,請執行此操作。它應該只是將新散列與舊散列進行比較以確保它們不匹配。 – RockyFord 2012-08-14 06:21:45

回答

1

創建我的下一個庫,並使用下列內容:

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; 
    } 
} 

More Information at the : Zend Manual 向下滾動到或發現:

注:校驗上下文

在源頁面。代碼在其下面給出,解釋也是如此。

希望它有幫助! :)