![]() |
validation class 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 class and callback functions. (/showthread.php?tid=19012) |
validation class and callback functions. - El Forum - 05-25-2009 [eluser]nealumney[/eluser] I have a callback function I want to call in a number of controllers, something like this: Code: function checkpostcode($postcode) I call the helper before the validation rules are set thus: Code: $this->load->helper('checkpostcode'); And my validation rule array entry looks like this: Code: array('field' => 'postcode','label' => 'Postcode must be valid','rules' => 'trim|required|callback_checkpostcode'), Do validation callbacks have to sit within the controller? Or am I doing something wrong? Thanks Neal validation class and callback functions. - El Forum - 05-25-2009 [eluser]Dam1an[/eluser] Yes, callback functionc currently need to be in the scope of the controller ![]() You could always put it in a MY_Controller, then it would be available to all controllers validation class and callback functions. - El Forum - 05-25-2009 [eluser]TheFuzzy0ne[/eluser] - Or you can extend the validation controller and add your custom methods, - Or you can store your validation rules in a config file (the form validation library supports this natively) - Or you can extend the validation class, and have it use a model or function or whatever. It's also possible to just alias the method from your controller: Code: function _custom_validation($str="") Or: Code: function _custom_validation($str="") |