![]() |
Form validation - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Form validation (/showthread.php?tid=12999) |
Form validation - El Forum - 11-07-2008 [eluser]callumd[/eluser] Hi there, CodeIgniter noob here, still trying to learn the ropes. So I've been playing with CI's Form_Validation class, and according to the user manual, the following is proper: Quote:$this->load->helper(array('form', 'url')); What struck me as odd about this is that all the form rules are being set before the system even knows if this is a form submission attempt. Seems like a real waste of resources, and bad logic. Is there a better way to do it, and if so, why doesn't it appear in the documentation? Thanks in advance. Form validation - El Forum - 11-07-2008 [eluser]McNoggin[/eluser] The first thing that set_rules does is check to see if there is any post data. Code: function set_rules($field, $label = '', $rules = '') Form validation - El Forum - 11-07-2008 [eluser]callumd[/eluser] Ahh, nice. Ok, that's *a bit* better.. Form validation - El Forum - 11-07-2008 [eluser]McNoggin[/eluser] If you are worried about the overhead from the function calls to set_rules you could always do that check yourself in the controller. if (count($_POST) > 0) { set_rules(...) } That way you are only doing count($_POST) once for an empty form instead of each rule. On the other hand for a form with data it will add an extra call to it. Form validation - El Forum - 11-07-2008 [eluser]callumd[/eluser] Thanks. |