![]() |
Validate Multiple Inputs Together? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Validate Multiple Inputs Together? (/showthread.php?tid=23347) |
Validate Multiple Inputs Together? - El Forum - 10-07-2009 [eluser]dustinsenos[/eluser] Heyo, I'm trying to validate a user's age. In order to do so, I need to validate the combination of three input boxes: month, day, year. Am I able to do so using custom _callbacks? Can I attach a _callback on the *entire* form before it's submitted? Can I throw a 'form validation error' myself outside of the _callback hook? Really appreciate the help, D Validate Multiple Inputs Together? - El Forum - 10-07-2009 [eluser]dustinsenos[/eluser] So I've spent some time and found a solution that doesn't require custom code and is quite straight forward. Synopses: Store each input's value in a private instance variable through a custom _callback applied to each input and then validate the combination of their values in a hidden input's custom _callback. Proof of Concept: views/ageView.php Code: <form> config/form_validation.php: Code: $config = array('ageCheck' => array(array( controller/AgeController.php Code: <?php Hope that helps! Cheers, Dustin Validate Multiple Inputs Together? - El Forum - 10-08-2009 [eluser]pistolPete[/eluser] You could simplify it a bit: You don't need monthCheck(), dayCheck() and yearCheck(). Code: public function finalAgeValidation() Another thought: Why don't you use a single input field where the date is entered like "01/02/1967"; you could then split the values into day, month and year in a single callback. Validate Multiple Inputs Together? - El Forum - 10-08-2009 [eluser]dustinsenos[/eluser] Ah good call on pulling out the $_POST vars. In regards to the single input field, I don't have control over the UI for this particular implementation. D |