Welcome Guest, Not a member yet? Register   Sign In
multiform validation
#1

[eluser]zilverdistel[/eluser]
I'm working on a form that consists of 4 pages. Everything worked fine, until I started to implement the repopulation of the 2nd form. After submission of the first form, obviously the 2nd is loaded. That's when I get a whole bunch of php error-messages (one per field), e.g.:

Quote:Message: Undefined property: CI_Validation::$address

When I hit reload, the page doesn't show the errors any more. My guess is that the first time the 2nd page loads, CI is confused by the already existence of the validation object from the 1st page. Now, I probably could just unset that object after I save the whole post-array from the 1st page to a session var (which I allready do - the saving), but I find that a not so neat solution.
#2

[eluser]xwero[/eluser]
Are the forms set up in one controller method or in four?
#3

[eluser]zilverdistel[/eluser]
I load the forms from 1 controller as 4 different views, as follows:

Code:
function index() {
        $schermNummer = $this->session->userdata('schermNummer');
        // validatie regels en veldnamen bevestigen
        $this->validation->set_rules($this->_getValidatieregels($schermNummer));
        $this->validation->set_fields($this->_getVeldnamen($schermNummer));

        if ($this->validation->run() == FALSE) {    
            // laad het huidige scherm opnieuw in
            $this->load->view('aanvraagformulier'.$schermNummer);    
        }
        else {    
            if ($schermNummer < 5) { // dit vermijdt dat we een onbestaand scherm opvragen
                // bewaar de gegevens in een sessievar array
                $this->session->set_userdata('invoerGegevens'.$schermNummer,$this->input->post());
                // laad het volgende scherm in
                $schermNummer++;
                $this->session->set_userdata('schermNummer',$schermNummer);
            }
            $this->load->view('aanvraagformulier'.$schermNummer);  
        }
}
#4

[eluser]xwero[/eluser]
try
Code:
function index() {
        $schermNummer = $this->session->userdata('schermNummer');
        

        if ($this->validation->run() == FALSE) {    
            // laad het huidige scherm opnieuw in
            // validatie regels en veldnamen bevestigen
             $this->validation->set_rules($this->_getValidatieregels($schermNummer));
             $this->validation->set_fields($this->_getVeldnamen($schermNummer));
            $this->load->view('aanvraagformulier'.$schermNummer);    
        }
        else {
            // validatie regels en veldnamen bevestigen
            $this->validation->set_rules($this->_getValidatieregels($schermNummer+1));
            $this->validation->set_fields($this->_getVeldnamen($schermNummer+1));  
            if ($schermNummer < 5) { // dit vermijdt dat we een onbestaand scherm opvragen
                // bewaar de gegevens in een sessievar array
                $this->session->set_userdata('invoerGegevens'.$schermNummer,$this->input->post());
                // laad het volgende scherm in
                $schermNummer++;
                $this->session->set_userdata('schermNummer',$schermNummer);
            }
            $this->load->view('aanvraagformulier'.$schermNummer);  
        }
}
#5

[eluser]zilverdistel[/eluser]
that didn't work, but thanks for pointing out my mistake. Only in the case the form validated true, I need to reset the validation rules and fields to those of the next form. Here's what works now:

Code:
function index() {
        $schermNummer = $this->session->userdata('schermNummer');
        
        // validatie regels en veldnamen bevestigen
        $this->validation->set_rules($this->_getValidatieregels($schermNummer));
        $this->validation->set_fields($this->_getVeldnamen($schermNummer));

        if ($this->validation->run() == FALSE) {    
            // laad het huidige scherm opnieuw in
            $this->load->view('aanvraagformulier'.$schermNummer);    
        }
        else {    
            if ($schermNummer < 5) { // dit vermijdt dat we een onbestaand scherm opvragen
                // validatie regels en veldnamen bevestigen
                $this->validation->set_rules($this->_getValidatieregels($schermNummer+1));
                $this->validation->set_fields($this->_getVeldnamen($schermNummer+1));
                // bewaar de gegevens in een sessievar array
                $this->session->set_userdata('invoerGegevens'.$schermNummer,$this->input->post());
                // laad het volgende scherm in
                $schermNummer++;
                $this->session->set_userdata('schermNummer',$schermNummer);
            }
            $this->load->view('aanvraagformulier'.$schermNummer);  
        }




Theme © iAndrew 2016 - Forum software by © MyBB