Welcome Guest, Not a member yet? Register   Sign In
Form Validation callback rules in controllers are viewable URLs
#1

[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?
#2

[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)
#3

[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?
#4

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

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

doh Confusedhut:
#6

[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.
#7

[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)
#8

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




Theme © iAndrew 2016 - Forum software by © MyBB