How to show validation errors using redirect in codeigniter?

后端 未结 4 1791
迷失自我
迷失自我 2020-12-31 04:50

I have been dealing with a problem for a while. How can I set the validation errors using redirect in a function? This is the code I have in my controller :

         


        
4条回答
  •  孤城傲影
    2020-12-31 05:15

    finally i got a solution for the redirect with validation_errors

    This is using to pass the validation_errors in the session data, i do it like this

    if ($this->form_validation->run()) {
            $data = array(
                'email' => $this->input->post('email'),
                'is_login' => true
            );
            $this->session->set_userdata($data);
            redirect($this->input->post('redirect'));
        }
        else
        {
            $data = array (
                'errors' => validation_errors(),
                'is_login' => false
            );
            $this->session->set_userdata($data);
            redirect($this->input->post('redirect'));
        }
    

    and in the page i used

            $this->session->set_flashdata('redirectToCurrent', current_url());
    
        if ($this->session->userdata('is_login'))
        {
            echo "You are using this as : 
    " . $this->session->userdata('email'); echo "
    Logout"; } else { echo form_open('login'); echo "" . $this->session->userdata('errors'); echo "email : " . form_input('email'); echo "Password : " . form_password('password'); echo form_submit('submit', 'Login'); echo form_hidden('redirect',$this->uri->uri_string()); echo form_close(); }

    I wish you like this fast solution

提交回复
热议问题