Welcome Guest, Not a member yet? Register   Sign In
Validation across 3 forms
#1

[eluser]jt`[/eluser]
I'm currently following this tutorial on validation using CI's built-in validation class:

http://ellislab.com/codeigniter/user-gui...ation.html

That example assumes you only have one page for input. What if I want to spread it out over 3 pages?

Currently, I'm storing all POST variables inside of session variables, in order to remember user input as they fill out forms across 3 pages. I can explain the reasoning if necessary, but ultimately I'll want to WRITE to the database after the 3rd and final form page is submitted.

Each page should go through server-side validation, and I currently am doing that on form page 1, but when I try and follow the above tutorial for form page 2, I run into two problems:

1) My URL isn't updating, it's just showing www.fu.bar/register_step1 (when in reality, once the first form is fully validated, it should load the view AND the url www.fu.bar/register_step2)

2) I'm getting errors on form page 2 for fields, they look like this:

Undefined property: CI_Validation::$textLocationName_error
Message: Undefined property: CI_Validation::$textStreet_error
Message: Undefined property: CI_Validation::$textCity
Message: Undefined property: CI_Validation::$textCity_error

For #2: I'm trying to basically pre-populate the fields if the page reloads and not every field is validated. I'm showing errors right next to each element using this syntax:

<?php echo $this->validation->textLocationName_error; ?>

===

Could anyone chime in and help me do this form validation across multiple pages? I'm following the steps in CI's Form Validation almost verbatim, so that's what most of my code looks like.
#2

[eluser]Bramme[/eluser]
i'd do smth like this

Code:
function step1() {
    // process first form
    // set rules, fields

    if($this->validation->run() != false) {
        // process $_POST into a session
        redirect('step2');
    } else {
        $this->load->view('firstform');
    }
}
function step2 () {
    // process second form
    // set rules, fields

    if($this->validation->run() != false) {
        // process $_POST into a session
        redirect('step3');
    } else {
        $this->load->view('secondform');
    }

}
You get the picture
#3

[eluser]jt`[/eluser]
This fixes the URL problem, however using redirect() seems to not be passing my POST variables to the next page?

I'm using the CI profiler, and when I load views, the form submission will also send POST variables--not when I use redirect() though... :-\

**EDIT: I understand I'm supposed to store the POST variables into session data from the controller, which I've done.

This has fixed my problem, I can now store the session variables, not worry about POST variables, and keep URLs updated and clean. Wonderful and thank you for the help =]
#4

[eluser]indocoder[/eluser]
another way to do this is by using hidden input, and pass it page by page, but I still prefer using session.




Theme © iAndrew 2016 - Forum software by © MyBB