CodeIgniter Forums
Re-Direct vs Load View - Help Please! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Re-Direct vs Load View - Help Please! (/thread-60297.html)



Re-Direct vs Load View - Help Please! - El Forum - 02-24-2014

[eluser]Hayezb[/eluser]
Hello!

I'm fairly new to CodeIgniter and I'm having some issues with re-direct vs loading my view when a form is submitted successfully and/or unsuccessfully. I want to use view, because with re-direct I'm having to put all my validation errors and POST data in sessions which is very annoying.

Here's a break down of the user process...

1.) User selects a company from a data table.
2.) User chooses to Add Location for this company and the form opens up with following URL: http://virtue-dev/administration/vendors/add_vendor_location/2

How do I load this view without having to do a re-direct?

Will not work:
Code:
$this->load->view('administration/header');
$this->load->view('administration/vendors/add_vendor_location/ID Goes Here');
$this->load->view('administration/footer');

I get the following error:
Code:
Unable to load the requested file: administration/add_vendor_location/2.php








Re-Direct vs Load View - Help Please! - El Forum - 02-24-2014

[eluser]Ckirk[/eluser]
You shouldn't have to worry about input and errors.
In short you should use $this->load->view() when you need to retain the input data and redirect() when you're done.
Something like this:

Code:
function theform()
{
  if ($this->form_validation->run() == TRUE)  // If no validation errors
  {
    // Insert code to handle form input
  
    // We no longer need the input data so redirect to start with a clean slate - especially if the page we're loading now is the form
    redirect('xxx/xxx');
  }

  // We'll only get here if form_validation is false
  $this->load->view('theFormView', $this->data);
}  /* End of function theform() */

I'm just off to bed so may have misunderstood your question but I hope this helps Smile