![]() |
how to use form validation to compare date? - if not possible accept a parallel solution. - 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: how to use form validation to compare date? - if not possible accept a parallel solution. (/showthread.php?tid=29639) |
how to use form validation to compare date? - if not possible accept a parallel solution. - El Forum - 04-16-2010 [eluser]Spectruman[/eluser] I have the following fields start date and end date start time end time. I need to do some checking to allow inclusion of data. Verifies that the start date is greater than the end date is also the same with the start time and end time and not allow inclusion of data if the start time is 12:00 and 14:00 hours late this time would be prohibited. Code: $this->form_validation->set_rules('dateStart','Date start','trim|required'); I would have this function to validate. Code: function compareDataTime($dateStart,$timeStart,$dateEnd,$timeEnd){ how to use form validation to compare date? - if not possible accept a parallel solution. - El Forum - 04-16-2010 [eluser]Kamarg[/eluser] Callback functions as explained in the user guide seem to be just what you're looking for. how to use form validation to compare date? - if not possible accept a parallel solution. - El Forum - 04-16-2010 [eluser]Spectruman[/eluser] [quote author="Kamarg" date="1271455255"]Callback functions as explained in the user guide seem to be just what you're looking for.[/quote] understand the function, the problem is how to pass all parameters to the function you want. For the tutorial I call only for item validation. as in the example: Code: $ this-> form_validation->set_rules('username', 'Username', 'callback_username_check'); Code: $ This-> form_validation->set_rules('dateStart', 'Start Date', 'trim|required|callback_compareDataTime'); how to use form validation to compare date? - if not possible accept a parallel solution. - El Forum - 04-19-2010 [eluser]Spectruman[/eluser] anyone have any solution for it? how to use form validation to compare date? - if not possible accept a parallel solution. - El Forum - 04-19-2010 [eluser]LuckyFella73[/eluser] Hi spectruman, I didn't test the script but you could do it this way: 1. set up a hidden form field (called "hidden_field" in my script) and validate: Code: $this->form_validation->set_rules('dateStart', 'Start Date', 'trim|required'); This way you just check your callback function one time - what should be enough. how to use form validation to compare date? - if not possible accept a parallel solution. - El Forum - 04-19-2010 [eluser]Kamarg[/eluser] Perhaps try something like Code: $this-> form_validation->set_rules('dateStart', 'Start Date', 'trim|required|callback_compareDataTime[' . $this->input->post('post_var_to_compare_to') . ']'); You'll need to change the parameters that compareDataTime expects and you won't be able to store the rules in a config file this way but it should do the trick. |