![]() |
form_validation->run() not working as expected - 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->run() not working as expected (/showthread.php?tid=26399) |
form_validation->run() not working as expected - El Forum - 01-12-2010 [eluser]Unknown[/eluser] I am learning to use CI (need to use it to re-write an existing app) and have run into an issue where Code: form_validation->run() Code: <?php The web form is displayed properly. If I enter incorrect values (or fail to enter a value) for one of the fields being validated, I expect to get an error message. Instead, the test: Code: if ( $form_return = $this->form_validation->run() == FALSE ) is FALSE (form_validation->run() returns TRUE). Every time. When I use validation->run() the test succeeds (validation->run() returns FALSE). I am using CodeIgniter 1.7.2 and would like to use the Form_validation library as it lets me set custom error messages. Is there some trick that I'm missing? Thanks! form_validation->run() not working as expected - El Forum - 01-12-2010 [eluser]JHackamack[/eluser] I believe your second test: if ( $form_return = $this->form_validation->run() == FALSE ) { } is incorrectly written as its both setting values and comparing values, I would instead try $form_return = $this->form_validation->run(); if($form_return == FALSE ) { } Does that work correctly? form_validation->run() not working as expected - El Forum - 01-12-2010 [eluser]Dyllon[/eluser] This isn't a bug, you are setting your rules incorrectly so when you run the validation it doesn't have any rules to validate against so it returns TRUE. Read the userguide section for form_validation, the method for setting rules that you are using got deprecated with the old validation library. form_validation->run() not working as expected - El Forum - 01-12-2010 [eluser]Unknown[/eluser] It was the set_rules() invocation that caused the problem. That may have come from following an older tutorial or user guide. Everything's working properly now. The offending code now looks like this: Code: // set validation rules Thanks for your help! |