how to use form validation to compare date? - if not possible accept a parallel solution. |
[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){
[eluser]Kamarg[/eluser]
Callback functions as explained in the user guide seem to be just what you're looking for.
[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');
[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.
[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. |
Welcome Guest, Not a member yet? Register Sign In |