CodeIgniter Forums
Form Validation callback rules in controllers are viewable URLs - 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: Form Validation callback rules in controllers are viewable URLs (/showthread.php?tid=15773)



Form Validation callback rules in controllers are viewable URLs - El Forum - 02-14-2009

[eluser]webbower[/eluser]
I just discovered that if I create a function in my Controller to use as a callback rule in my Form Validation rules, the callback function can be requested as a viewable page. Might I suggest that callback functions in Controllers be defined as a private function and then just prefix "callback" instead of "callback_" to it in the rules for Form Validation to use it.

Thoughts?


Form Validation callback rules in controllers are viewable URLs - El Forum - 02-14-2009

[eluser]Colin Williams[/eluser]
Just underscore your callbacks and then use callback__function in your rules. (That's two underscores, since "callback_" is the prefix and "_function" is the function to call, which is private)


Form Validation callback rules in controllers are viewable URLs - El Forum - 03-16-2009

[eluser]Shrike67[/eluser]
I get an error:

PHP Fatal error: Call to private method Users::_email_check() from context 'CI_Form_validation' in /system/libraries/Form_validation.php on line 589

and I use callback__email_check

and private function _email_check($email)

any suggestion?


Form Validation callback rules in controllers are viewable URLs - El Forum - 03-16-2009

[eluser]Colin Williams[/eluser]
Easy. Make your function public.


Form Validation callback rules in controllers are viewable URLs - El Forum - 03-16-2009

[eluser]Shrike67[/eluser]
[quote author="Colin Williams" date="1237223025"]Easy. Make your function public.[/quote]

doh Confusedhut:


Form Validation callback rules in controllers are viewable URLs - El Forum - 06-28-2009

[eluser]krif[/eluser]
This really is an issue for me too. Callback functions should not be URL-accessible. Any suggestions?

EDIT: Ah, sorry, my mistake. Two underscores indeed work. Forgot to use an underscore for the first parameter of the set_message() function.


Form Validation callback rules in controllers are viewable URLs - El Forum - 08-05-2009

[eluser]krif[/eluser]
because I just came across the same issue again, here's an example:

if your private callback function is something like this:

[code]function _my_private_callback_function($variable) {}[code]

make sure that within this you set your custom error message as follows

[code]$this->form_validation->set_message('_my_private_callback_function', 'Error message text');[code]

(notice the underscore here also)


Form Validation callback rules in controllers are viewable URLs - El Forum - 09-10-2009

[eluser]macigniter[/eluser]
Cool. I just had the same question and this seems to work well!