![]() |
callback validation help - 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: callback validation help (/showthread.php?tid=26383) |
callback validation help - El Forum - 01-12-2010 [eluser]dadamssg[/eluser] im trying to write functions that check dates but im not sure how to use them in a validation script. I know you can use callbacks for your own functions but i don't know how to use it for this. Code: function date_exists($month,$day,$year) i need to use this twice...once for the start date and one for the end date. i can't see how i can do that using the $rules[] callback validation help - El Forum - 01-12-2010 [eluser]JHackamack[/eluser] Why not combine start date and end date before you pass them in with a unique character ("-","/","_", etc) and then explode that character inside the function? callback validation help - El Forum - 01-12-2010 [eluser]dadamssg[/eluser] i don't understand how you use a callback to pass data into it...from the user guide you use this Code: $this->form_validation->set_rules('username', 'Username', 'callback_username_check'); how do you pass info INTO that username check when your setting the ruls? callback validation help - El Forum - 01-12-2010 [eluser]danmontgomery[/eluser] I believe callback functions for form_validation can only accept one parameter, which is the value of the field being validated. You would probably be passing it a string in the format of m/d/Y, or something similar. Code: function date_exists($date) then: Code: $this->form_validation->set_rules('start_date', 'Start Date', 'callback_date_exists'); callback validation help - El Forum - 01-12-2010 [eluser]JHackamack[/eluser] It will only pass one parameter into the callback: http://www.codeignitor.com/user_guide/libraries/form_validation.html#callbacks Thats why i was suggesting combining the strings of the date with a unique character you can use php explode on. You might notice in the example routines they have a username_check($str) where $str is the one variable you can pass in. You can also call $this->input->post or $this->input->get inside your function so if your variables are posted you can reference them that way without having to combine them beforehand. callback validation help - El Forum - 01-12-2010 [eluser]dadamssg[/eluser] well i would need to pass in six parameters: month, day , year, hour, min, am/pm. Not six for this checkdate function but i will be writing other functions that deal with timestamps. noctrum, i don't think that would work. I have my date and time selection broken down into dropdowns for each. Its not just a text field where they would input "1/12/2010". They have to select day, month, year, hour, min, am/pm from drop downs and radio buttons. callback validation help - El Forum - 01-12-2010 [eluser]JHackamack[/eluser] If you have them broken up and using post variables use the following callback_date_exists function date_exists() { $month = $this->input->post('month'); $day = $this->input->post('day'); $year = $this->input->post('year'); etc } that should work for your needs |