2011-05-07 132 views
1

我正在爲用戶模型做一些基本的模型驗證,但不幸的是驗證工作不正常。Cakephp 1.3模型驗證錯誤

這是我的錯誤:

  1. 如果「要求」時,錯誤消息總是出現
  2. 如果「要求」未使用,沒有錯誤消息,即使不正確的變量輸入(即:打字字母A的名稱。
  3. 電子郵件被驗證的 「name-gmail.com」 這顯然不是一個電子郵件

幫助!請!

這是在我的模型我驗證變量:

var $validate = array(
    'name' => array(
     'length' => array(
      'rule' => array('minLength', 2), 
      'message' => 'Please enter your first name (more than 2 chars)', 
      'required' => true, 
     ), 
    ), 
    'username' => array(
     'length' => array(
      'rule'  => array('minLength', 5), 
      'message' => 'Must be more than 5 characters', 
     ), 
     'alphanum' => array(
      'rule'  => 'alphanumeric', 
      'message' => 'May only contain letters and numbers', 
     ), 
     'unique' => array(
      'rule'  => 'isUnique', 
      'message' => 'Already taken', 
      'required' => true, 
     ), 
    ), 
    'email' => array(
     'email' => array(
      'rule'  => 'email', 
      'message' => 'Must be a valid email address', 
     ), 
     'unique' => array(
      'rule'  => 'isUnique', 
      'message' => 'Already taken', 
     ), 
    ), 
    'password' => array(
     'empty' => array(
      'rule'  => 'notEmpty', 
      'message' => 'Must not be blank', 
      'required' => true, 
     ), 
    ), 
    'password_confirm' => array(
     'compare' => array(
      'rule'  => array('password_match', 'password', true), 
      'message' => 'The password you entered does not match', 
      'required' => true, 
     ), 
     'length' => array(
      'rule'  => array('between', 6, 20), 
      'message' => 'Use between 6 and 20 characters', 
     ), 
     'empty' => array(
      'rule'  => 'notEmpty', 
      'message' => 'Must not be blank', 
     ), 
    ), 
); 

回答

0

看一看the docs。我不確定電子郵件驗證失敗。如果您想「更好」驗證,請嘗試:

'email' => array(
    'rule' => array('email', true), 
    'message' => 'Must be a valid email address' 
)