2016-01-11 94 views
0

我正在使用codeigniter表單驗證。但我有問題,即密碼匹配不適合我。當回調方法顯示「電子郵件不存在」時, 那時候,所有驗證都正常工作。php驗證錯誤

public function forget_password() { 

    $this - > form_validation - > set_rules('email', 'email', 'trim|required|valid_email|callback_verifyUser', 
     array(
      'required' => 'You must enter your email!', 
      'valid_email' => 'Enter valid email!', 
      //'is_unique' => ' is already exists' 
     ) 
    ); 
    $this - > form_validation - > set_rules('password', 'password', 'trim|matches[confirm_password]|required|min_length[6]', 
     array(
      'required' => 'You Must Enter Password', 
      'matches' => 'Password Must Match with Confirm_password', 
      'min_length' => 'Minimum contain 6 charaters', 
     ) 
    ); 
    $this - > form_validation - > set_rules('confirm_password', 'confirm_password', 'trim|required', 
     array(
      'required' => 'You Must Enter Password', 
     ) 
    ); 
    if ($this - > form_validation - > run() === true) { 
     $this - > load - > view('forget-password'); 
     $this - > load - > view('template/footer'); 
    } else { 
     $this - > load - > view('forget-password'); 
     $this - > load - > view('template/footer'); 
    } 
} 

public function verifyUser() { 

    $email = $this - > input - > post('email'); 
    if ($this - > e_model - > login_view($email)) { 
     $result = $this - > e_model - > reset($email); 
     $this - > session - > set_flashdata('flsh_msg', '<div class="alert alert-success text-center">New password created successfully!</div>'); 
     redirect(current_url()); 
     return true; 
    } else { 
     //$this->form_validation->set_message('verifyUser','Email does not exists!'); 
     return false; 
    } 
} 
+0

您不需要在數組的最後一個對象之後使用逗號(,)。 – Dray

+0

是的,我已經刪除它,但它不起作用。 –

回答

0

我使用了一個簡單的機制來驗證passwords..check會否與URS工作太..

public function validation() { 
     $this->db->select('name,email,type,id'); 
     $this->db->where('email', $this->input->post('email')); 

     $this->db->where('password', $this->input->post('password')); 


     $result = $this->db->get('custsp'); 

     if ($result->num_rows() == 1) { 
      return $result->result(); 
     } else { 
      return false; 
     } 
    } 
0

你都做了表單驗證這麼多漫長的編碼.... !當你已經在使用內置庫

使用電子郵件的可用性一個簡單的驗證規則

$this->form_validation->set_rules('email', 'email', 'required|is_unique[users.user_email]'); 

其中「用戶」是你的表名和「USER_EMAIL」是你的領域 不要用你的自定義代碼和密碼檢查...

$this->form_validation->set_rules('password', 'Password', 'required|matches[passconfirm]'); 

就是這樣! 我希望你能得到它。對於細節你應該正確引用表單驗證的文檔。