![]() |
Form validation callback functions file - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Form validation callback functions file (/showthread.php?tid=39464) |
Form validation callback functions file - El Forum - 03-11-2011 [eluser]Mike Chojnacki[/eluser] Hi, I'm trying to figure out a way to have a file with callback functions for the form validation callback rules. Having to copy paste and hard-code the ones you need into every controller is rather un-intuitive. I have tried to use it as a helper and as a library, ultimately the problem boils down to the function not having access to the form_validation object and no way to pass it along when calling the callback_ functions in the form rules. config/form_validation.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); application/library Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); application/helper Code: function password_check($str) function_exists('password_check) returns true, but the callback isn't initialized either way. Has anyone found a workaround for this problem? I refuse to believe that having the same function hard-coded in every controller that needs it. Form validation callback functions file - El Forum - 03-11-2011 [eluser]InsiteFX[/eluser] Might work in a MY_Controller, but I have not tried it. Give it a try and see if it will work. InsiteFX Form validation callback functions file - El Forum - 03-14-2011 [eluser]Mike Chojnacki[/eluser] [quote author="InsiteFX" date="1299877744"]Might work in a MY_Controller, but I have not tried it. Give it a try and see if it will work. InsiteFX[/quote] Hi InsiteFX, thanks for your advice. It did try it, but it did not work straight away. Here is the "fix" I applied. applications/libraries/MY_Form_validation.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); system/libraries/form_validation.php [start at line 589] Code: // MODIFIED Now, you can just add functions like "password_check" to MY_Form_validation and call them wherever you want, if no function is found it will fall back and check in the controller if that callback validation function exists there. I just did it quickly now, does anyone have any input on as how to accomplish this effect without having to directly edit a system library file? I really like this way much better cos I can have all my callbacks in one file and not clutter my controllers with them and reproduce code over several pages. Form validation callback functions file - El Forum - 03-20-2011 [eluser]junkwax[/eluser] Exactly what I needed, thx. I will use that method until something similar is natively included in CI |