当我按提交当前密码,新密码和确认密码时,它一直显示错误[无法访问与您的字段名称当前密码相对应的错误消息。检查当前密码(],在当前密码的文本字段旁边。请帮忙,谢谢!
下面是我的控制器:
public function chgpass()
{
//$this->load->view('chgpass');
//$this->load->library('form_validation');
$this->form_validation->set_rules('cpassword','Current Password','trim|required|max_length[20]|min_length[6]|callback_checkCurrentPassword|xss_clean');
$this->form_validation->set_rules('npassword','New Password','trim|required|max_length[20]|min_length[6]');
$this->form_validation->set_rules('copassword','Confirm Password','trim|required|max_length[20]|min_length[6]');
if($this->form_validation->run() == FALSE){
$this->load->view('chgpass');
}else{
$this->load->model('Form_model');
$this->load->view('chgpass');
$query = $this->Form_model->checkCurrentPassword($this->input->post('cpassword'));
if($query){
$query = $this->Form_model->saveNewPassword($this->input->post('npassword'));
if($query){
$this->session->sess_destroy();
$data['error']='Password Change Successfully!';
$this->load->view('chgpass',$data);
}else{
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error. Please try again later!!!</div>');
redirect('main/chgpass');
}
}
}
}
}
下面是我的模型:
public function checkCurrentPassword($cpassword)
{
$this->db->select('id');
$this->db->where('id',$this->session->userdata('id'));
$this->db->where('password',$this->input->post('cpassword'));
$query = $this->db->get('users');
if($query->num_rows() > 0){
return true;
}else{
$this->form_validation->set_message('checkCurrentPassword','Wrong old password!');
return false;
}
}
public function saveNewPassword($npassword)
{
$data = array(
'password' => $npassword
);
$this->db->where('id',$this->session->userdata('id'));
$this->db->where('password',$this->input->post('cpassword'));
$query = $this->db->update('users',$data);
if($query){
return true;
}else{
return false;
}
}
试试这个: 控制器
public function chgpass()
{
if ($this->input->post()) {
$this->load->library('form_validation');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_error_delimiters('', '<br />');
if ($this->form_validation->run()) {
$resetPasswordArray = array(
'Password' => md5(md5($time_now) . md5($this->input->post('resetPassword'))),
'Last_Updated' => $time_now,
'Record_Created' => $time_now
);
if ($this->Consumer_model->updatepassword($this->input->post('id'), $resetPasswordArray)) {
parent::json_output(["id" => $this->input->post('id'), "code" => 1]);
return;
}
} else {
echo validation_errors();
die;
}
}
return "0";
}
//model
function updatepassword($user_id, $user_details_array) {
return $this->db->where('id', $user_id)->update('tablename', $user_details_array);
}