Welcome Guest, Not a member yet? Register   Sign In
How to pass dynamicly params to a rules config file?
#1

[eluser]Unknown[/eluser]
I need to use dynamicly params for form validation rules. These parameters are specific to each user. I use config file for rules and I can't to understand what is the right way for passing of these parameters to validation function. I found only 1 solution - extend run function in form_validation class. Which passes arguments to the function of validation based on regular expressions. Tell me, if I chose the right way or such tasks can be solved in another way?


In form_validation.php config file:
Code:
.............
$config['myrule'] = array(
    array(
          'field' => 'fieldname',
          'label' => 'fieldlabel',
          'rules' => 'trim|required|min_length[3]|my_callback[@param1]',
          ),
.............

In controller:

Code:
......
if ($this->form_validation->run('myrule',array('param1'=> $param1)) != FALSE) {
Do some code...
}
......

In MY_Form_validation.php:

Code:
public function run($group = '', $params = array()) {
.....code for Extend run method....
}
......
function my_callback($param1 = FALSE) {

}
......




Theme © iAndrew 2016 - Forum software by © MyBB