![]() |
Validation help required - how can I trigger a validation message from my code... - 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 help required - how can I trigger a validation message from my code... (/showthread.php?tid=59812) |
Validation help required - how can I trigger a validation message from my code... - El Forum - 11-22-2013 [eluser]CrisThompson[/eluser] Hi, I'm working on my first CI project, although have tons of PHP experience. I have a form capturing a date or birth as 3 separate fields, and in the form validation, I need to convert these 3 fields to a timestamp, make sure the user is older that 18, and then pass back a fail validation message if they are not. I can do the date manipulation, but how do I trigger a validation message from my php - it's based on 3 fields not 1, so how does callback work? Cris. Validation help required - how can I trigger a validation message from my code... - El Forum - 11-22-2013 [eluser]Otemu[/eluser] Hi, Validation can be called on any field, for instance if you have separate input for day, month and year, you could have the callback set on year Code: $this->form_validation->set_rules('year', 'year', 'callback_date_check'); Hope that helps Validation help required - how can I trigger a validation message from my code... - El Forum - 11-22-2013 [eluser]CroNiX[/eluser] The first parameter of set_message must be the same name as the validation method it's being set in or the validator won't be able to retrieve the error message for whatever field it was assigned to, so in this case it would be $this->set_message('date_check'). Cris, I don't think you should convert it to a timestamp in the validation. You should only check whether the supplied date was valid, and that the person was over 18. If the form passes validation (meaning the date was valid along with all other fields), your model should be the one to convert it to a timestamp before it inserts/updates into the db. Code: //grab year, month and days fields Validation help required - how can I trigger a validation message from my code... - El Forum - 11-25-2013 [eluser]CrisThompson[/eluser] Thanks for your replies... All sorted. |