使用回调进行CI表单验证

时间:2017-01-20 14:42:40

标签: php codeigniter validation callback

我正在使用CI表单验证创建更改密码,并通过回调模型设置规则。

docker-engine

这是用于检查密码然后更改密码的回调函数:

public function change_password()
{
    $this->form_validation->set_rules('current_password', 'Current Password', 'trim|required|callback_change');
    $this->form_validation->set_rules('new_password', 'New Password', 'trim|required|min_length[5]|max_lenght[10]');
    $this->form_validation->set_rules('conf_new_password', 'Confirm New Password', 'trim|required|matches[new_password]');

    if ($this->form_validation->run() == FALSE) 
    {
        $this->load->view('change_pass');
    }
}

这是更改密码表单

function change()
{
    $session_data = $this->session->userdata('logged_in');
    $username = $session_data['username'];
    $this->User_model->check_pass($username);
    $rst = $this->User_model->check_pass($username);

    foreach ($rst as $row) 
    {
        $db_password = $row->password;
    }

    if (md5($this->input->post('current_password')) == $db_password) 
    {
        //model for change password here

        $this->form_validation->set_message('change', 'Change Password Success');
        return FALSE;
    }
    else
    {
        $this->form_validation->set_message('change', 'Wrong current password');
        return FALSE;
    }
}

表单验证仅在当前密码为false或表单中的所有字段为空时才有效,但如果当前密码为true或与数据库表单匹配,则验证不会运行false,尽管新密码和确认新密码不是比赛。请帮我修理一下,如果我的英语或我的问题不清楚,我很抱歉。非常感谢

0 个答案:

没有答案