直接页面时无法显示验证错误消息

I can't show validation error message when direct page

我有登录检查器的这个功能,当 $email$password 错误时我想添加重定向到另一个页面,比如在 facebook 页面上登录,当 $email$password incorect 他们指向不同的页面但仍然登录页面(但不是同一页面)并将错误消息 $email$password 发送到页面

function basisdata_cek($password){
    $email = $this->input->post('email');
    $result = $this->login->login($email,$password);
    if($result){
        $sess_array = array();
        foreach($result as $row){
            $sess_array = $arrayName = array('kode_daftar'=>$row->kode_daftar, 'email'=>$row->email, 'password'=>$row->password);
            $this->session->set_userdata('logged_in',$sess_array);
        }
        return true;
    }else{
        $this->form_validation->set_message('basisdata_cek','invalid email or password');
        return false;
    }
}

但问题是当我像这样添加重定向页面时

}else{
    redirect(base_url('index.php/login'),'refresh');
    $this->form_validation->set_message('basisdata_cek','invalid email or password');
    return false;
}

邮箱和密码错误时仍然是直接页面,但不会显示form_validation的消息。

It is not possible to get form_validation message if you redirect. But you can use flashdata for this.

将此 $autoload['libraries'] = array('session'); 添加到 application/config/autoload.php 并将此代码放入您的登录页面

if ($this->session->flashdata('basisdata_cek')) {
    echo '<div class="alert alert-warning">';
    echo '<p>' . $this->session->flashdata('basisdata_cek') . '</p>';
    echo '</div>';
  } 

并在 redirect 之前放置 flash $this->session->set_flashdata 而不是 $this->form_validation->set_message :

 }else{
    $this->session->set_flashdata('basisdata_cek', 'Invalid email or password');
    redirect(base_url('index.php/login'),'refresh');        
    return false;
  }