How to show validation errors using redirect in codeigniter?

后端 未结 4 1818
迷失自我
迷失自我 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:16

    As per my comment:

    function index()
    {
        $this->load->library('form_validation');
        $data = array
        (
            'Param' => 'Value'
        );
        if($this->input->post('cellphone', true) !== false)
        {
            if($this->form_validation->run() != FALSE)
            {
                echo '
    ' . print_r($_POST, true) . '
    '; } } $this->load->view('index', $data); }

    First, you need to change your form so it points to the current page, i.e. current_url() or site_url('controller/index').

    When you go to the index without posting, it will simply skip the validation. Upon submitting your form, it will run the validation.

    You can then use the built in form_error or validation_errors methods to display the errors within your index view.

提交回复
热议问题