• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Form Help

#12
[eluser]bretticus[/eluser]
Quote:If they enter the wrong data I’d like to return to the homepage or something giving the errors? Do I have to embed the home page data here again or can I call the index() function passing in the errors?

I see you trying to do a redirect on form errors. This is not the right approach in CI. Unless you use sessions to serialize your errors, you lose access to them in your redirect. I always load the default view for the controller. Validation, by default, will always fail when the controller loads. This let's me load the form on a standard page load and reload the form (because it's the same view) on subsequent form validation errors. Best of all, the form values that did not fail are still filled in and I can use form_error() to show an error right next to the field(s) that failed. I'm not sure what your strategy is, but this should work regardless of whether or not the current controller is the path specified in the form action.

Code:
// rules, etc.
if($this->validation->run() == FALSE) {
//load default view for this controller action/method/function
} else {
//everything is great. upload video, call model methods and redirect to video.
}


If the form is available on all views in every sidebar, just make a view with the markup for that single form and "include" it into each of your views. You can use the standard php include function but I find it easier (allthough questionable form) to just call it as a view inside the view that is called from the controller. Because that form is always included, you can always send the errors back to the view via the form validation class and display them (although this scenario means most likely that they will always end up landing on your addvideo action of your controller. However, you could serialize the referrer and redirect to the original view upon a successful upload. Or, better yet, redirect to the page that has the newly-uploaded video.)

Another method people are found of that I don't particularly agree with is calling multiple views in the controller like so:

Code:
if($this->validation->run() == FALSE) {
$this->load->view('header', $data);
$this->load->view('sidenav', $data);
$this->load->view('videos', $data);
$this->load->view('footer', $data);
}

Each of your layouts are made up of these individual views. The reason I don't like it is because if you ever have a designer or someone less savvy of what is going on in your application that needs to work on it, he or she will be very confused (I work with designers.)


Messages In This Thread
Basic Form Help - by El Forum - 08-03-2009, 08:27 AM
Basic Form Help - by El Forum - 08-03-2009, 08:57 AM
Basic Form Help - by El Forum - 08-03-2009, 08:59 AM
Basic Form Help - by El Forum - 08-03-2009, 09:01 AM
Basic Form Help - by El Forum - 08-03-2009, 11:43 AM
Basic Form Help - by El Forum - 08-03-2009, 01:36 PM
Basic Form Help - by El Forum - 08-04-2009, 04:39 PM
Basic Form Help - by El Forum - 08-04-2009, 07:41 PM
Basic Form Help - by El Forum - 08-05-2009, 07:14 AM
Basic Form Help - by El Forum - 08-05-2009, 09:37 AM
Basic Form Help - by El Forum - 08-05-2009, 10:18 AM
Basic Form Help - by El Forum - 08-05-2009, 11:11 AM
Basic Form Help - by El Forum - 08-05-2009, 12:23 PM
Basic Form Help - by El Forum - 08-05-2009, 12:41 PM
Basic Form Help - by El Forum - 08-05-2009, 01:01 PM
Basic Form Help - by El Forum - 08-05-2009, 01:09 PM
Basic Form Help - by El Forum - 08-11-2009, 07:51 AM
Basic Form Help - by El Forum - 08-11-2009, 08:39 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.