codeigniter中的登录表单验证无效

时间:2014-02-18 10:23:58

标签: codeigniter

登录表格验证对我不起作用。它适用于注册,但是当我使用我的登录表单尝试相同的事情。有些检查在代码点火器中无法正常工作。 这是我的代码。我运行代码,它进入我的其他条件,但不显示验证错误。 前两个检查为我创建问题。当输入为空或有些输入错误的电子邮件格式时。

function index() {
    $data['nav']= $this->category_model->view_brands();

    if($_POST) {
        $data['error'] = '';
        $this->load->library('form_validation');
        $this->form_validation->set_rules('email_login', 'Email', 'required|valid_email');
        $this->form_validation->set_rules('password_login', 'Password', 'required');

        if($this->form_validation->run() !== FALSE) {
            $log_in = $this->login_model->login_beyond(
                        $this->input->post('email_login'),
                        md5($_POST['password_login'])
                      );

            if($log_in !== FALSE) {
                echo "<script>window.location.href=\"../index.php\"</script>";
            } 
            else {
                // Set your error message
                $data['error'] = 'Wrong Username/Password';
            }
        } 
        else {
            // Set the validation errors
            echo "it came heere but donot show errors"; 
            $data['error'] =validation_errors();
        }
    }

    $data['login_not'] = "login";
    $this->template->load('template','client/login_view',$data);
}

1 个答案:

答案 0 :(得分:0)

最好写if ($this->form_validation->run() === FALSE)并从那里开始工作,而不是写if($this->form_validation->run() !== FALSE)。这是因为在表单验证中,当run()返回true时,可能是因为它评估了所有结果而没有找到任何错误或者给出的值甚至不存在所以错误验证没有适用于不存在的值。

Lemme知道它是否有效

相关问题