0

我的 _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;
    }
}
4

1 回答 1

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;
        }   
}
于 2012-06-13T04:14:36.927 回答