![]() |
Validation rules from both config and controller - 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 rules from both config and controller (/showthread.php?tid=34779) |
Validation rules from both config and controller - El Forum - 10-09-2010 [eluser]crikey[/eluser] Hi all, I'm wondering if anyone has ever used a combination of loading form validation rules from a config file and then adding new rules later in the controller. I want to load some rules from a file to keep them out of the controller (there's lots of fields in my form) and then conditionally add new rules depending on the POST input - if certain fields have data then I want to validate it, but they're not required fields. As far as I can tell from the user guide, rules from a config file are only processed when the $this->form_validation->run() method is called, and by then it's too late to add other rules. Does anyone know a way around this that will allow me to do what I want? Thanks. Validation rules from both config and controller - El Forum - 10-12-2010 [eluser]sketchynix[/eluser] I'm not sure I understand your reason for doing this. Perhaps I misread it but from what I gather.. "if certain fields have data then I want to validate it, but they’re not required fields".. Why can't you just exclude the 'required' rule in your array for that field? ie if username were required and age wasn't... Code: array( Validation rules from both config and controller - El Forum - 11-27-2010 [eluser]freeman[/eluser] Hi, maybe this should help. Quote:if certain fields have data then I want to validate it, but they’re not required fields maybe something like Code: if($this->input->post('email')) Or a combination of rules from config file as well as rules in your controller Code: // in your "test" controller Code: // my_form_validation.php Code: // app/config/form_validation.php |