Welcome Guest, Not a member yet? Register   Sign In
Passing multiple arguments to callback function in form_validation class
#1

[eluser]Jayakrishnan[/eluser]
Hi,

Is it possible to pass multiple arguments to callback functions for form validation purposes ?
I saw how to pass a single parameter from the following thread.

Passing a dynamic variable as a parameter to a form validation callback function

Can somebody help me out with passing multiple parameters ?

Thanks,
Jayakrishnan GK
#2

[eluser]Jayakrishnan[/eluser]
Any updates ?
#3

[eluser]InsiteFX[/eluser]
Just what are you trying to do?

Give an example and some code.

InsiteFX
#4

[eluser]CroNiX[/eluser]
CI natively only allows for a single parameter. You can either extend CI to allow for more, or use a simple solution that I have been using to get around it. For the 2nd parameter, you can do something like:
Code:
$parameter = 'first_arg' . '||' . 'second_arg' . '||' . 'third_arg';
so your rule would look something like:
Code:
$this->form_validation->set_rules('some_field', 'Some Field Name', 'callback__my_callback_function[first||second||third]');

Then in the callback function:

Code:
function _my_callback_function($field_value, $second_parameter){
    list($first_param, $second_param, $third_param) = split('||', $second_parameter);
    //now you can do something with the params
    if($first_param == 'insert')
    {
        //do something..
    }
}
#5

[eluser]Publisher1[/eluser]
[quote author="CroNiX" date="1272656773"]CI natively only allows for a single parameter. You can either extend CI to allow for more, or use a simple solution that I have been using to get around it. For the 2nd parameter, you can do something like:
Code:
$parameter = 'first_arg' . '||' . 'second_arg' . '||' . 'third_arg';
[/quote]

Hi CroNiX

Thanks a lot for this solution. I tried to realaze it on this way, but that didn't worked for me. Then i tried whout double pipes, i tried with # and + , these two symbols has worked. I am using CI 2.1.3 , maybe this version strips the pipe in the callback funcions.

This solution worked for me :-) :

Code:
required|trim|max_length[50]|xss_clean|callback_userdata_used_and_not_mine[users++username]

Code:
public function userdata_used_and_not_mine($s_value, $s_second_callback_parameter) {
        
    // To use more additional parameters that only 1 additional for callback functions
    $a_second_callback_parameter = explode('++', $s_second_callback_parameter);

    // bla..
}




Theme © iAndrew 2016 - Forum software by © MyBB