SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can't pass variables between different steps

    I have a form that has multiple steps, when they push submit, the script does the error checkings and validation, and if errors are found, it should send them back to Step 1 with a paragraph on what errors they have. Here's an abstract of the script:

    PHP Code:
    if ($step=="") {
      
    $step 1;
    }

    if (
    $step==1) {
    //shows the errors if there was any
    if ($error_list) {
      foreach (
    $error_list as $errormsg) {
        echo 
    "$errormsg<br />";
      }
    }

    //shows the form
    <form action=$PHP_SELF?step=2>
    //input boxes, etc
    </form>
    //END Step 1

    if ($step==2) {
    //does the error check functions...
    //if there is any errors, it'll set
    //$error_list with an array of errors
    error_check(is_empty($name));
    error_check(is_empty($address));
    ...

    //if there's any errors, send them
    //back to Step 1 and tell user to fix
    //them up
    if ($error_list) {
      
    header ("Location: $PHP_SELF?step=1");
    }

    //no errors, show confirmation page
    Here are the info you entered:
    Name$name
    Address
    $address
    ...
    END Step 2

    // more steps...
    ... 
    The above is an interpetation of what my script looks like.

    The problem is, when they submit in Step 1, Step 2 does all the error checking, and founds errors so send user back to Step 1 with the header(), but once it sends them back, all the variables get lost, and as far as Step 1 is concern, $error_list was never created, so it doesn't show the error messages.

    I could do it so if Step 2 finds errors, it shows the form again, but that's repeated code of the form...

    How can I send $error_list from Step 2 back to Step 1?

  2. #2
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do this
    if ($error_list) {
    header ("Location: $PHP_SELF?step=1&error1=$error1&error2=$error2");
    }

    or to make it look clean, put them in a session.

    John
    Last edited by johnn; Sep 22, 2001 at 06:25.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •