我使用回调函数来检查电子邮件是否处于活动状态: 我的控制器没有访问回调函数。
我的控制器代码:
function index() {
//Session redirection
header('Last-Modified:'.gmdate('D, d M Y H:i:s').'GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0',false);
header('Pragma: no-cache');
$this->session->unset_userdata('created_user_id');
$this->session->unset_userdata('created_user_type');
$this->session->unset_userdata('edit_user_type');
if ($this->input->server('REQUEST_METHOD') === 'POST'){
$this->form_validation->set_rules('email', 'Email ID', 'trim|required|valid_email');
$this->form_validation->set_rules('terms', 'Terms', 'trim|required');
if($this->input->post('email'))
{
$this->form_validation->set_rules('email', 'Email ID', 'callback_email_check');
} echo "out"; die;
$this->form_validation->set_error_delimiters('<div class="error_user" style="color:red">', '</div>');
if($this->form_validation->run()){
if($this->input->post('Join')!="") {
$this->session->set_userdata('join_email', $this->input->post('email'));
redirect(base_url().'caregivers/my-account');
}
}
}
$this->load->view('site/landing-page');
}
我的回调函数代码:
public function email_check(){
$get_status = $this->web_user_model->get_status($this->input->post('email'));
if($get_status['is_active']=='1')
{
$this->form_validation->set_message('email_check','Email ID already Exits');
return FALSE;
}else{
return TRUE;
}
}
我不知道我在哪里犯了错误。 谁能帮我??? 提前谢谢..
答案 0 :(得分:1)
您设置了两倍验证规则:
$this->form_validation->set_rules('email', 'Email ID', 'trim|required|valid_email');
....
if($this->input->post('email'))
{
$this->form_validation->set_rules('email', 'Email ID', 'callback_email_check');
}
这是没用的,因为您已经将电子邮件字段设置为必需,因此验证规则已经检查了if。
尝试:
$this->form_validation->set_rules('email', 'Email ID', 'trim|required|valid_email|callback_email_check');
你的回调函数也应该有一个参数
public function email_check($email)
{
$get_status = $this->web_user_model->get_status($email);
...