1

I am validating a form on many view that are generated by the third URL segment.

The URL: http://example.com/listings/item/12 (The 12 will change based on item)

Both my functions are below, my question is, when the validation fails how to I refresh the page with the 3rd segment and show the validation errors?

P.S: I have already tried redirect() but the validation errors don't remain.

Thank You.


This is the "item" function

    public function item()
{

    if ($this->session->userdata('is_logged_in'))
    {
        $id = $this->uri->segment(3);
        $this->load->model('listings_model');

        if ($data['things']= $this->listings_model->get_item($id))
        {
            $this->load->view('list/item_view',$data);
        }
    }
    else
    {
         $this->unauth();
    }
}


This is my validations

    public function get_email()
{

    $this->load->library('form_validation');


        $this->form_validation->set_rules('captcha', 'Captcha', 'required|trim|callback_check_captcha' );


        if ($this->form_validation->run() == FALSE)
        {
           $this->item();
        }
        else
        {
            $this->load->model('listings_model');

            if ($this->listings_model->update_listing())
            {
                echo "Good";
            }

        }
}
4

2 に答える 2

1

You can use the following code to redirect to your page when error occurs. you can put it in your controller when error occurs.

redirect('listings/item/12/error_message_goes_here', 'location');
exit;

And in your view check weather the fourth parameter exists. if the fourth exists then show the error

if(!empty($this->uri->segment(4))){

   $this->output->set_output($this->uri->segment(4));

}

So you the point is: you redirect and in your redirect you pass the error message, then in view if error message exists you display it.

于 2013-03-23T10:26:31.033 に答える
0

You can set uri segment by setting form action attribute.

form_open("controller/method/segments/to/retain", array('method' => 'post'));
于 2018-11-23T02:40:34.670 に答える