CodeIgniter Forums
Pass extra parameter to an anonymous validation function - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Pass extra parameter to an anonymous validation function (/showthread.php?tid=1369)



Pass extra parameter to an anonymous validation function - Frank - 03-04-2015

hi,

I see in the documentation that, it is possible to pass a extra parameter to a callback function in the form validation system.
And it works.

But what about when you want to use an anonymous function instead of a callback one ? i've tried to do this way but it didn't worked

PHP Code:
$this->form_validation->set_rules('my_field[]''my_field',
 
       array(array('my_function['.$extra_parameter.']',
 
         function($value$extra_parameter)
 
         {
 
           // My code
 
         }) )); 

thanks


RE: Pass extra parameter to an anonymous validation function - Frank - 03-12-2015

finally it is possible to do the following with php >= 5.3 :

PHP Code:
$this->form_validation->set_rules('my_field[]''my_field',
       array(array('my_function',
         function($value) use ($extra_parameter)
         {
           // My code
         }) ));