Passing multiple arguments to callback function in form_validation class |
[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
[eluser]InsiteFX[/eluser]
Just what are you trying to do? Give an example and some code. InsiteFX
[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'; 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){
[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'; 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) { |
Welcome Guest, Not a member yet? Register Sign In |