CodeIgniter Forums
Need advice on form error handling - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Need advice on form error handling (/showthread.php?tid=45511)

Need advice on form error handling - El Forum - 09-24-2011

Hi all,

I'm quit new to CI and love the framework. Since I'm rewriting my current website to a new multilingual with modern features, I question myself on how to do the form error handling best (whats best practice) in CI.
Keep in mind that (later on) I want to add AJAX to the form (which is completely new to me).

Your advise/suggestions are more than welcome and very appreciated.

I submit the form like this
<?= form_open('contact/process', array('id' =>'Myform')); ?>

When something goes (technically) wrong (validation or database) I have a few options;

1. set error data and jump to an errorfunction ie:
$this->errData['errorMessage'] = $this->lang->language['db_error_heading'];
My URL will look like sitename/contact/process
This has a disadvantage that the url is not changed (I would like to see contact/error), because this is more clear to the user (I think)

2. set Flash_data and redirect to the errorfunction ie:
$this->session->set_flashdata('Database', $this->lang->language['db_error_heading']);
My URL will look like sitename/contact/error and is more appropriate.

3. set flash_data and redirect to a new 'error' controller
$this->session->set_flashdata('Database', $this->lang->language['db_error_heading']);
My URL will look like sitename/error and is more appropriate.(I think)

All of the above have pro's and con's, please advise me.
Thanks in advance.