Welcome Guest, Not a member yet? Register   Sign In
Validation callback issue
#1

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

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

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

Thanks.
#4

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB