Callback doesn't work, what's wrong? - 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: Callback doesn't work, what's wrong? (/showthread.php?tid=55977) Pages:
1
2
|
Callback doesn't work, what's wrong? - El Forum - 11-19-2012 [eluser]ReyPM[/eluser] Hi, I've this code in my template: Code: <label>Código UNESCO:</label><?php echo form_error('unescocode'); ?> And this other code in my controller: Code: $this->load->library('form_validation'); When I send the form and leave id_unesco as 0 non error is displayed and form is send, why? where I´m wrong? Callback doesn't work, what's wrong? - El Forum - 11-19-2012 [eluser]PhilTem[/eluser] Because you need to check for a string provided as $value in the validation function. If you check for 0 it translates to "If $value is not set or empty" Thus: Code: public function check_unesco($value = '0') { Callback doesn't work, what's wrong? - El Forum - 11-19-2012 [eluser]ReyPM[/eluser] Thanks PhilTem, now validation works but I don't know how to show message associated to error. I've tried: Code: <?php echo form_error('id_unesco'); ?> Callback doesn't work, what's wrong? - El Forum - 11-19-2012 [eluser]CroNiX[/eluser] Because the error message name must be the exact same as the rule name. Code: function myrule($value) //rule name Your rule name is "check_unesco", but your message name is "check_unesco_value", so it doesn't match up. Callback doesn't work, what's wrong? - El Forum - 11-19-2012 [eluser]ReyPM[/eluser] Still not working :-( my code now look like this: Code: public function check_unesco($value) { Code: <?php echo form_error('check_unesco'); ?> Callback doesn't work, what's wrong? - El Forum - 11-19-2012 [eluser]CroNiX[/eluser] Show in your controller where you are setting the validation rule for the field (or fields) you are using this callback on. Callback doesn't work, what's wrong? - El Forum - 11-19-2012 [eluser]ReyPM[/eluser] Here is (just the relevant part not the whole code): Code: public function create() { Callback doesn't work, what's wrong? - El Forum - 11-19-2012 [eluser]CroNiX[/eluser] It shouldn't matter, but try putting xss_clean last in your rules. Any function that can alter the value (like htmlentities, xss_clean, etc) should go after all rules that only return a boolean true/false. The only exception to this that I can think of would be trim, which you would want first like you have to clear entries that only contain spaces. Callback doesn't work, what's wrong? - El Forum - 11-19-2012 [eluser]CroNiX[/eluser] Oh, but to SHOW that error, you use the NAME of that form element that the rule was applied to, not the RULE name. Code: <?php echo form_error('id_unesco'); ?> Callback doesn't work, what's wrong? - El Forum - 11-19-2012 [eluser]ReyPM[/eluser] Does not work yet :-( |