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

[eluser]ChristiaanT[/eluser]
Hello,

I'm using CI for almost 2 years now and this is the first time I ever post something in here. It proofs how easy CI is! But...

Currently I'm working on a site that has a lot forms to display. All the forms starting with standard personal data. So I thought to have a standard view for this personal data and for every other form I'm loading another form view to. Works perfect.

Now I'm handling the data after posting it, but now I want to validate the personal fields AND the other fields at once. I made a form_validation.php config file with all rules and fields set up in different sections (so 'default' for the default fields, and 'blabla' for the blabla fields). But when I try to run multiple validations it won't work. I'm doing like this:

form_validation.php config file

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'
            ),

Controller
Code:
function send($formname)
    {        
        $data['formname'] = $formname;

        if ($this->form_validation->run('default') == FALSE && $this->form_validation->run($formname) == 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');

        } else {

It does handle the first run (default), but after that it won't run the second. Or at least it doesn't give me the errors when I'm not filling in the form complete.

Do you guys have a clue how to handle this? A solution would be to put all the rules and fields in one section, but I don't like to have double data in my app. Another solution would be to array_merge the two arrays from the form_validation.php config file and then 'load' the config file. But I couldn't find a way to do this. The previous version did it that way, didn't it?

I hope you can help me out. Thanks...


Messages In This Thread
Run multiple form validation from config file - by El Forum - 07-18-2009, 02:42 PM
Run multiple form validation from config file - by El Forum - 07-19-2009, 12:39 AM
Run multiple form validation from config file - by El Forum - 07-19-2009, 12:41 AM
Run multiple form validation from config file - by El Forum - 07-19-2009, 05:14 AM
Run multiple form validation from config file - by El Forum - 07-20-2009, 02:58 AM
Run multiple form validation from config file - by El Forum - 07-20-2009, 03:28 AM
Run multiple form validation from config file - by El Forum - 07-20-2009, 03:35 AM
Run multiple form validation from config file - by El Forum - 07-20-2009, 03:37 AM
Run multiple form validation from config file - by El Forum - 07-20-2009, 03:49 AM
Run multiple form validation from config file - by El Forum - 07-27-2009, 05:22 PM
Run multiple form validation from config file - by El Forum - 07-27-2009, 10:13 PM
Run multiple form validation from config file - by El Forum - 07-27-2009, 10:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB