我正在使用codeigniter表单验证。但我有问题,就是密码匹配对我不起作用。当回调方法显示“电子邮件不存在”时, 那个时候,所有的验证工作正常。
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 :(得分:0)
我使用了一种简单的机制来验证密码。检查它是否也适用于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;
}
}
答案 1 :(得分:0)
你已经为表单验证做了很多冗长的编码.... 在使用内置库时,请不要使用自定义代码
使用一个简单的验证规则来实现电子邮件可用性
$this->form_validation->set_rules('email', 'email', 'required|is_unique[users.user_email]');
用户&#34;用户&#34;是你的表名和&#34; user_email&#34;是你的领域 和密码检查...
$this->form_validation->set_rules('password', 'Password', 'required|matches[passconfirm]');
那就是!! 我希望你能得到它。有关细节,你应该正确参考表格验证的文件。