CodeIgniter Forums
Validation callback issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Validation callback issue (/thread-9419.html)



Validation callback issue - El Forum - 06-24-2008

[eluser]EEssam[/eluser]
Hi,

I have something like this in my controller:

...
$rules['parentid'] = "callback_parental_check";
...

function parental_check($parent)
{

}

It's working fine but I need to pass another parameter for parental_check function to compare it with $parent variable. How can this be done?

Thanks.


Validation callback issue - El Forum - 06-24-2008

[eluser]Bramme[/eluser]
If you look at the validation library and other callbacks, you notice how some use smth like callback[variable]. When I had a look at the library, I noticed the functions off those callbacks had $variable set as the second parameter... Not sure if it's that easy, but it won't hurt to try, won't it?


Validation callback issue - El Forum - 06-24-2008

[eluser]EEssam[/eluser]
I don't get it. How should my code look like?

Thanks.


Validation callback issue - El Forum - 06-24-2008

[eluser]EEssam[/eluser]
By the way, I'm not even able to set a var at the beginning of the Controller, like

var blablabla;

The callback function can't see it Sad


Validation callback issue - El Forum - 06-24-2008

[eluser]mdavis1982[/eluser]
Hi...

It's really easy...

Just do:

Code:
$rules['parentid'] = 'callback_parental_check[blah]';

function parental_check($parent, $variable)
{
  // $variable == 'blah' now, because it's been passed in!
  // Insert code for doing the check or whatever
}

Hope that helps!

Matt


Validation callback issue - El Forum - 06-24-2008

[eluser]EEssam[/eluser]
That worked, thank you so much.