CodeIgniter回调用户名和;密码信息

时间:2012-06-13 03:35:29

标签: php validation codeigniter

我的_callback函数存在一些问题:

我想用以下代码实现的目标是:

  • 如果用户详细信息不正确,则显示$message错误(当前未显示)
  • 如果没有输入任何内容并且已输入提交,我希望它显示“请登录”。

控制器:

public function loginUser() {
    $this->form_validation->set_rules('userEmail','Username', 'required|valid_email|trim|max_length[99]|xss_clean');
    $this->form_validation->set_rules('userPassword','Password', 'required|trim|max_length[200]|xss_clean|callback__checkUsernamePassword');

    if($this->form_validation->run() === TRUE) {

    }
}

回调:

function _checkUsernamePassword() {
    $username = $this->input->post('userEmail');
    $password = $this->input->post('userPassword');
    $user = $this->user_model->check_login($username,$password);

    if(! $user)
    {
        $data['contentMangement'] = $this->options_model->systemOptions();
        $data['pageTitle'] = 'Add User';
        $data['message'] = form_error('userEmail','<div class="alert alert-error">', '</div>'); 
        $this->load->view('_assets/header', $data);
        $this->load->view('addUser', $data);
        $this->load->view('_assets/footer');
        $this->form_validation->set_message('_checkUsernamePassword', 'Sorry %s is not correct.');
        return FALSE;
    }else{
        echo 'sheepdogs';
        return TRUE;
    }
}

1 个答案:

答案 0 :(得分:0)

我通过改变我的_callback解决了这个问题:

 function _checkUsernamePassword() {

        $username = $this->input->post('userEmail');
        $password = $this->input->post('userPassword');

        $user = $this->user_model->check_login($username,$password);

        if(! $user)
        {
            $this->form_validation->set_message('_checkUsernamePassword', 'Sorry the details you provided have not been found');
            return FALSE;
        }else{
            return TRUE;
        }   
}