CodeIgniter Forums

Full Version: Form Validation callback rules in controllers are viewable URLs
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

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

El Forum

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

El Forum

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

El Forum

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

El Forum

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

doh Confusedhut:

El Forum

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

El Forum

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

El Forum

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