![]() |
validation and callback functions - 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: validation and callback functions (/showthread.php?tid=11068) |
validation and callback functions - El Forum - 08-25-2008 [eluser]jbads[/eluser] Hi what is the best way to do the following: I have a form where users must enter 2 different dates. One for the actual date of the event they're promoting and one for the date their promotional material is to go live on my website. For each date I would like 3 dropdowns one each for day, month and year. At the validation stage I would like to check whether the date has not already passed and that the event date comes after the promotional date. I tried this in my controller Code: $e_date = $this->input->post('event_date_day').'/'.$this->input->post('event_date_month').'/'.$this->input->post('event_date_year'); And this in the callback function Code: function _valid_date($x_date){ It seems callback functions will only send the value of the current input field and wont pass the callback function the extra variable containing the date... So It's only passing the callback the year field instead of all three fields such as 01/10/09 Is there a way to pass a callback function those variables. I have also tried setting those variables inside the callback function but then how do I check both dates individually and return the message to the correct date entry section of the form? validation and callback functions - El Forum - 08-25-2008 [eluser]Colin Williams[/eluser] $this->input->post('other_field') validation and callback functions - El Forum - 08-25-2008 [eluser]jbads[/eluser] Please eleborate? validation and callback functions - El Forum - 08-25-2008 [eluser]Colin Williams[/eluser] In your custom callback function, use $this->input->post() to capture the other field because you cannot pass two vars into a callback. validation and callback functions - El Forum - 12-26-2008 [eluser]Chee Wai[/eluser] It didn't work because in your case: $rules['event_date'] = 'trim|xss_clean|min_length[2]|callback__valid_date[$e_date]'; you enclosed your php variable in single quotes. the date field is passed as the literal $e_date. To pass the value, you should use double quotes: $rules['event_date'] = "trim|xss_clean|min_length[2]|callback__valid_date[$e_date]"; or string concatenation: $rules['event_date'] = 'trim|xss_clean|min_length[2]|callback__valid_date[' . $e_date . ']'; validation and callback functions - El Forum - 12-26-2008 [eluser]Colin Williams[/eluser] I didn't think you could even pass extra values to the callback functions. I thought the callback only ever was supplied one argument, the value of the field being validated. |