![]() |
Form validation fails to prevent data entry to db - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Form validation fails to prevent data entry to db (/showthread.php?tid=57948) |
Form validation fails to prevent data entry to db - El Forum - 04-28-2013 [eluser]alex646[/eluser] Hey guys, Can somebody help me with the following issue I have: Form validation fails to prevent data entry to db after lets say I omit required field. I get the form_error messages that field is required but form still inserts data to db which is blank. Maybe I'm missing something : ( Thanks! My controller that handles the form validation Code: public function newpost(){ My model: Code: class Add_post_model extends CI_Model { Form validation fails to prevent data entry to db - El Forum - 04-28-2013 [eluser]CroNiX[/eluser] Because you're getting $title and $post from input::post(), which never returns NULL. They will return the value or boolean FALSE if it doesn't exist. Quote:CodeIgniter comes with three helper functions that let you fetch POST, COOKIE or SERVER items. The main advantage of using the provided functions rather than fetching an item directly ($_POST['something']) is that the functions will check to see if the item is set and return false (boolean) if not.However, I'm not sure why you are running validation on those fields and ALSO within your add_post(). You don't need the checking within add_post(), just move add_post() to be within your validation success statement. Code: if ($this->form_validation->run() == FALSE) Code: public function add_post($title, $post) { Form validation fails to prevent data entry to db - El Forum - 04-28-2013 [eluser]alex646[/eluser] Thanks a lot! I'm learning ci and some things are just harder to grasp at first than others, but your post helped me to get my head around it : ) Thanks! |