2016-01-11 79 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]'); 

就是这样! 我希望你能得到它。对于细节你应该正确引用表单验证的文档。