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