extending validation - 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: extending validation (/showthread.php?tid=12015) |
extending validation - El Forum - 10-02-2008 [eluser]dimis[/eluser] I make a Quote:MY_Validation extends CI_Validationat application/libraries and I make this function Code: function _check_setbox($val) { Code: $fields['collection']= "collection"; What is wrong? Dimis extending validation - El Forum - 10-02-2008 [eluser]dimis[/eluser] I change, I put the function at my controller but it does not work also. Code: function _check_setbox($val) { extending validation - El Forum - 10-02-2008 [eluser]xwero[/eluser] If you put a rule in the MY_Validation file you can caal it as the CI rules. You don't have to use the get_instance function as the $CI is a class variable in the Validation library. Also you don't have to use the set_message function because you can add the message to the language file if you want. extending validation - El Forum - 10-02-2008 [eluser]dimis[/eluser] I put at MY_Validation Code: function _check_setbox($val) { Code: $rules['material'] = "required|_check_setbox($material_id)"; extending validation - El Forum - 10-02-2008 [eluser]xwero[/eluser] It doesn't work because you add (fieldname) to the rule Code: $rules['material'] = "required|_check_setbox"; extending validation - El Forum - 10-02-2008 [eluser]TheFuzzy0ne[/eluser] I believe you also need to call on your function by enclosing your arguments within evaluation brackets. Like this: Code: $rules['collection'] = "required|callback__check_setbox[$collection]"; It may also be simpler for you to just throw your validation functions into a helper file, then you can load the helper file, and call on the function as if it were a native PHP function, and without having to extend the validation class. |