Welcome Guest, Not a member yet? Register   Sign In
Run multiple form validation from config file
#11

[eluser]David Johansson[/eluser]
I just read through the source of the form validation library. By the look of it you can only add the set of rules one time per controller. You can run the validation more times but since it is not likely that you $_POST data array will change the result is probably the same as when you run it the first time.
#12

[eluser]David Johansson[/eluser]
Hmm, actually, it looks like you can set the rules first, and then run them all if we have the rules like ChristiaanT wrote:
[quote author="ChristiaanT" date="1247967763"]
Code:
$config = array(
    'default' => array(
        array(
            'field' => 'person_name',
            'label' => 'Name',
            'rules' => 'required'
            ),
        array(
            'field' => 'person_email',
            'label' => 'Email',
            'rules' => 'required'
            ),
        ),
    'blabla' => array(
        array(
            'field' => 'blabla_date',
            'label' => 'Blabla date',
            'rules' => 'required'
            ),
[/quote]

We could then do:

Code:
$data[formname] = $formname;
$this->form_validation->set_rules($config['default']);
$this->form_validation->set_rules($config[$formname]);
if ($this->form_validation->run() == FALSE){      
    $this->load->view('default/header', $data);
    $this->load->view('form/form_persondata', $data);
    $this->load->view('form/form_'.$formname, $data);    
    $this->load->view('form/form_footer', $data);
    $this->load->view('default/footer');
}
If a rule exists for the same field in both the default and the form specific rule set only the later one will be user (this might be good for overriding).




Theme © iAndrew 2016 - Forum software by © MyBB