![]() |
extending CI_Validation class with MY_Validation class to add validation 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: extending CI_Validation class with MY_Validation class to add validation functions. (/showthread.php?tid=2742) |
extending CI_Validation class with MY_Validation class to add validation functions. - El Forum - 08-22-2007 [eluser]flyer[/eluser] Hi all, Really struggling to get to grips with a customised MY_Validation. The situation is I want a customised function similar to xss_clean which basically converts a text input string to a modified version (e.g. 'Bob' going to 'Hello Bob Hello'). I also want the validation function to be globally accessible i.e. not just a callback function within the Controller. To this end I created a very simple custom MY_Validation.php vaguely following the patterns of the xss_clean function: Code: MY_Validation.php: The code then used in the controller is: Code: function customiseStr() Code: <html> All looks very simple and as if it should work. Note the form simply submits to itself, then puts the modified string if available into the text input box. If I change customise_string to xss_clean in the $rules['customStr'] definition then works exactly how expected. i.e. on submit the string is xss_clean'ed then returned to the form and displayed in the text input box. When the customise_string function is called in the MY_Validation class, I have been able to determine that before the $_POST variable is changed it equals the correct posted value, i.e. inputed string. But after is changed it equals null. Is the problem that I need to treat the global $_POST in a special way when modifying it? Or is my code wrong in some other way? Many thanks in advance. Eddie extending CI_Validation class with MY_Validation class to add validation functions. - El Forum - 08-22-2007 [eluser]flyer[/eluser] Hmmm, oooops, using the + sign instead of . to concatenate strings alas!!! sorry feel free to delete this post. |