Welcome Guest, Not a member yet? Register   Sign In
Form validation - callback function question
#1

[eluser]Andrewkha[/eluser]
hi!

I have a question regarding form validation with the callback function.
The documentation says that I can pass the additional parameter like this

"callback_foo[bar]"

but what if bar is not static but variable?

For example, I'm developing a sports application.
Need to enter a game details, including the tour number, into the specific tournament. Each tournament has different number of tours which is stored in the DB.
So how can I pass the tournament id to the callback function to get the higher limit? Or how can I pass already retrieved from the DB value?
#2

[eluser]Andrewkha[/eluser]
Or is there any way to pass it from the form somehow?
#3

[eluser]CroNiX[/eluser]
Just pass the variable to the validation function.
Code:
$id = 'some_variable';
$this->form_validation->set_rules('field', 'Field', "required|callback_foo[$id]");

Code:
function foo($field_value, $params)
{
  //$params = 'some_variable';
}




Theme © iAndrew 2016 - Forum software by © MyBB