Whats the best way to handle the following situation in codeigniter:
Home controller has an index action and a submit action.
The submit action is used for a form submission. I want to load the page through the index controller though – including after form submission i.e. with form errors data to repopulate form inputs on error etc.
Whats the best way to do this – without having the index controller handle the main page loading and the form submission.
If you
redirect(), you won’t be able to useset_value()for re-populating your form fields.What’s easiest is having your index controller handle both the default load behavior, and the submission.
Alternatively, you can just set up your
indexandsubmitcontroller, and have them point at the same view, which detects ifvalidation_errors()are set and re-populates form fields accordingly.Third option (hackish): you could use flashdata to keep submission errors and the submitted form values across a redirect back to index. Something like this would work: