![]() |
Form validation: Callback not changing the input value - 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: Callback not changing the input value (/showthread.php?tid=20220) |
Form validation: Callback not changing the input value - El Forum - 07-02-2009 [eluser]Nis Sarup[/eluser] As I read the user guide any callback in a form validation rule should change the input value if the result returned from the callback function is anything but TRUE or FALSE. I can't get it to do that. I have a rule: Code: $rules['birthday'] = 'trim|required|callback__validate_birthday'; But Code: $this->input->post('birthday') Form validation: Callback not changing the input value - El Forum - 07-02-2009 [eluser]TheFuzzy0ne[/eluser] Welcome to the CodeIgniter forums. If the problem is with your callback, then it might be useful for you to post the code for it. Form validation: Callback not changing the input value - El Forum - 07-02-2009 [eluser]Nis Sarup[/eluser] Here is the callback: Code: function _validate_birthday() It looks at the 3 inputs for the birthday, makes the timestamp and returns it if everything is allright. Form validation: Callback not changing the input value - El Forum - 07-02-2009 [eluser]TheFuzzy0ne[/eluser] Are you absolutely sure that everything is all right? I'd suggest sticking a die($birthday) in before the return. Then you can be sure that a) It's being reached, and b) the format is what you're expecting it to be. Form validation: Callback not changing the input value - El Forum - 07-02-2009 [eluser]Nis Sarup[/eluser] I did. That's how I know it's being called. I stick die's all over the code when I can't get it to work. It returns a a unixtimestamp from the mktime() function. The rest of the validation works as well. It triggers a FALSE if I set my birthday to something less than 18 years ago. I even tried to make the calback return 'Some string" and the input was still unchanged. Form validation: Callback not changing the input value - El Forum - 07-02-2009 [eluser]TheFuzzy0ne[/eluser] I'm not entirely sure what's happening in that case, since it's always worked as expected for me. One problem I have noticed though, which is totally unrelated, is that the first parameter for $this->form_validation->set_message() should be '_validate_birthday' and not 'validate_birthday'. Form validation: Callback not changing the input value - El Forum - 07-02-2009 [eluser]TheFuzzy0ne[/eluser] Oh, and another thing. You're validating the day against the current year. Surely that's not right? Code: if (0 > $day || $day > (int)date('Y')) { Form validation: Callback not changing the input value - El Forum - 07-02-2009 [eluser]Nis Sarup[/eluser] Yeah. I had originally named the function without the starting underscore, but read that that was a bad thing to do. I just corrected those set_message's but it doesn't change anything. Here is the signup function that runs the validation: Code: function signup() I left in the die() for you. It outputs whatever I selected in the dropdown in the form. Not what the callback returns. Form validation: Callback not changing the input value - El Forum - 07-02-2009 [eluser]Nis Sarup[/eluser] [quote author="TheFuzzy0ne" date="1246552704"]Oh, and another thing. You're validating the day against the current year. Surely that's not right?[/quote] Hehe, you're right, those $day's should be $year's. Thanks. Form validation: Callback not changing the input value - El Forum - 07-02-2009 [eluser]TheFuzzy0ne[/eluser] I'm sorry, but unfortunately I'm about to go out for a few hours, so this will have to wait. If you're still stuck when I get back, I'll test the code, and see if I can get to the bottom of this. |