Validation ... callback doesn't get triggered - 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: Validation ... callback doesn't get triggered (/showthread.php?tid=8349) |
Validation ... callback doesn't get triggered - El Forum - 05-14-2008 [eluser]FinalFrag[/eluser] I'm just starting out with CodeIgniter and I ran up to a problem I cannot seem to fix. So I decided to pay another visit to the forums I have a simple form with 2 fields: username and password. I don't want to use the validation rules that come with CodeIgniter because I want to have more control over the error message the user gets. I currently have this code: Code: function login() { Can anyone tell me why _check_input is never called? Instead I just get redirected to 'home' if I leave all fields empty... Thanks is advance... Validation ... callback doesn't get triggered - El Forum - 05-15-2008 [eluser]xwero[/eluser] none of the fields are required which means the validation just skips them if they are empty. Because there is no output for the run method php will see this as true. The simplest way to fix this is to do this Code: if ($this->validation->run() === TRUE) Validation ... callback doesn't get triggered - El Forum - 05-15-2008 [eluser]FinalFrag[/eluser] Code: if ($this->validation->run() === TRUE) That doesn't work. I have tested this with the following code: Code: if ($this->validation->run() === true) { This always returns: Code: result: 1 So it always returns true... even if it shouldn't... Anyone else have a suggestion / solution? Validation ... callback doesn't get triggered - El Forum - 05-15-2008 [eluser]xwero[/eluser] Nice to know a void return is always 1. The next thing you can do is turn around your if Code: if (!$this->validation->run()) { Validation ... callback doesn't get triggered - El Forum - 05-15-2008 [eluser]FinalFrag[/eluser] Nope, still no luck... Validation ... callback doesn't get triggered - El Forum - 05-15-2008 [eluser]xwero[/eluser] The same as the true then but for false Code: if ($this->validation->run() === FALSE) { Validation ... callback doesn't get triggered - El Forum - 05-15-2008 [eluser]FinalFrag[/eluser] Nope, that's just another way to write the same thing, I think I need a different approach. I noticed that when I add a 'required' to the rules, it does work. But I also get the 'The ... field is required.'-message (which I obviously don't want)... Any more hints on this subject? Validation ... callback doesn't get triggered - El Forum - 05-15-2008 [eluser]xwero[/eluser] Maybe it is the trim function that is the cause, you could try this to be sure Code: $rules['username'] = 'trim'; Validation ... callback doesn't get triggered - El Forum - 05-15-2008 [eluser]xwero[/eluser] [quote author="FinalFrag" date="1210855936"]Nope, that's just another way to write the same thing, I think I need a different approach.[/quote] It's not another way it is a different way Code: !$variable Code: $variable == FALSE With Code: $variable === FALSE Validation ... callback doesn't get triggered - El Forum - 05-15-2008 [eluser]wiredesignz[/eluser] My 2c. @xwero: echoing TRUE always displays as 1 @Final: You will find the error messages in system/language/english/validation_lang.php, you could create your own version of these in application/language. Callbacks are never run for an empty input. So `trim|required` is your only choice, unless you create a MY_Validation extension. |