Aaargh!! What Am I Doing Wrong With This Callback? - 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: Aaargh!! What Am I Doing Wrong With This Callback? (/showthread.php?tid=10447) |
Aaargh!! What Am I Doing Wrong With This Callback? - El Forum - 07-31-2008 [eluser]Phil Norton[/eluser] Right, I've done callbacks before with no problems, but what should be very simple is taking me an age to get working. Perhaps it's a case of looking at the same thing for too long, so hopefully someone out here can spot what I'm doing wrong!! In my Controller: Code: $rules['start_time'] = "required|callback_timeCheck"; And then the validation in the same Controller: Code: function timeCheck($time) { If I leave the field blank, CI's "required" validation works and throws up an error. But if I type anything in the box, the error isn't being triggered. However, if I use the regex to check the string entered by doing this when I submit the form, I get the correct result so I know the regex is correct: Code: if (!ereg("^([0-1][0-9]|[2][0-3]):([0-5][0-9])$", $this->input->post('start_time'))) { Like I said, it's possible that I've been staring at it for so long now that the very obvious answer is laughing at me whilst staying hidden from my eyes!! Any help would be gladly appreciated! Phil Aaargh!! What Am I Doing Wrong With This Callback? - El Forum - 07-31-2008 [eluser]Yash[/eluser] change your function name I mean add _ like I've showed it.. A idea only Code: function _timeCheck($time) { Aaargh!! What Am I Doing Wrong With This Callback? - El Forum - 07-31-2008 [eluser]Phil Norton[/eluser] Nope, that doesn't work either. Anyone else? Aaargh!! What Am I Doing Wrong With This Callback? - El Forum - 07-31-2008 [eluser]Yash[/eluser] Try to echo $time if its coming check your if statement Aaargh!! What Am I Doing Wrong With This Callback? - El Forum - 07-31-2008 [eluser]Phil Norton[/eluser] I tried that to begin with in the callback: Code: function timeCheck($time) { But when I post data to the form, it's not echoing the "TESTING" statement at all, whether or not I'm putting a time in the correct format. Am I calling the callback correctly? Something must be wrong if it's not even echoing that statement, right? Code: $rules['start_time'] = "required|callback_ timeCheck"; This is driving me crazy! ;o) Aaargh!! What Am I Doing Wrong With This Callback? - El Forum - 08-04-2008 [eluser]Phil Norton[/eluser] D'oh! What a stupid mistake, basically, I'd wrongly nested the callback functions within another function in the controller, which is why they weren't working. Once I'd moved them, they worked perfectly!! Sorry for any inconvenience caused, and thanks for looking at it for me! Phil |