CodeIgniter Forums
Two Step Form with CI Validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Two Step Form with CI Validation (/showthread.php?tid=7170)



Two Step Form with CI Validation - El Forum - 03-28-2008

[eluser]adamfairholm[/eluser]
Hey there -

I've poked around for a bit and haven't found an answer to this, so here we go. May be an obvious answer but for some reason it isn't coming to me.

I'm trying to do a two step form with CI validation. So the process goes like this:

FORM 1 - User inputs some data, it gets validated by CI and the form data is passed to the next form.
FORM 2 - Some more info (dependent on the first form's info) is filled out.

The problem I'm running in to is being able to set validation for both of these forms. I know for CI validation to work your form action needs to be the same method that displays the form, which leaves me in a bind because if the second form validates it's going to just reload and if it doesn't it'll go back to the first form.

Here's some psuedo code:

Controller:
Code:
<?php

//Validation Rules for first_form

if ($this->validation->run() == FALSE) {$this->load->view('forms/first_form', $data);}
       else {
        //if validation says everything is cool, send data to second form.  
                
        $this->load->view('forms/second_form', $data);
        }

?>

Is there a much better way of doing this that I'm overlooking?


Two Step Form with CI Validation - El Forum - 03-28-2008

[eluser]nirbhab[/eluser]
1. After Validating FORM-1, store data to Session.
2. Than Redirect to second Method, totally independent of the first one (check for existing session, else redirect back to FORM-1)
3. Validate the Form-2.
4. SAVE FORM-1 (session data) to database(wht ever you want to do)
5. Save FORM-2 to Database.


Two Step Form with CI Validation - El Forum - 03-28-2008

[eluser]adamfairholm[/eluser]
Perfect! Exactly what I was looking for - much appreciated.