#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    40
    Rep Power
    2

    How do you send information from a from to 2 pages?


    I can send information from one page to another $_POST

    But how do I send information from a form from the second to the third page?

    Do I use a cookie or can I a simpler method?

    Thanks
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,143
    Rep Power
    9398
    This is typically done in one of two ways:
    1. The information from each page is stored in the session. This is best if you have full control over everything, most importantly the code.
    2. Each page submits data from the previous page as hidden fields (plus whatever new fields it has to add). This can mean you have to validate data a lot and so is only really worth considering if you're breaking an existing large form into multiple small pages and it's only the final page that does any real work (eg, validating or processing) with the data.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    40
    Rep Power
    2

    Re:


    How would one go about storing information in a session?

    I appreciate your help
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,143
    Rep Power
    9398
    1. Needs a session_start(), naturally.
    2. On the first page generate a fairly random ID. Stick that in the form as a hidden field, and in every subsequent form too.
    3. When each page is submitted, validate the data and store the array in $_SESSION[...][the random ID]. You can use a subarray for each page, or array_merge() everything together.
    4. Redirect to and/or show the next pages.
    5. Finally, all the data has been collected in there. Use it and unset() it.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,003
    Rep Power
    376
    Originally Posted by requinix
    1. Needs a session_start(), naturally.
    2. On the first page generate a fairly random ID. Stick that in the form as a hidden field, and in every subsequent form too.
    3. When each page is submitted, validate the data and store the array in $_SESSION[...][the random ID]. You can use a subarray for each page, or array_merge() everything together.
    4. Redirect to and/or show the next pages.
    5. Finally, all the data has been collected in there. Use it and unset() it.
    wrong answer :

    1. type in google.com in your fave browser
    2. search for "Sessions + PHP +tutorial" or something similar
    3. go to one of the links provided..

    see i got 3 steps to your 5

    but then again, i understand this might be hard for some to do..
  10. #6
  11. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,143
    Rep Power
    9398
    Oh yeah? How about one:

    1. Google it.

    Yeah, giving fewer steps doesn't make it better advice.

    Comments on this post

    • paulh1983 agrees : i was just hinting that the OP should have googled ;) if that wasnt clear
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    40
    Rep Power
    2

    Re:


    Thanks requinix for taking the time to answer.

    I will experiment and let you if it works.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    40
    Rep Power
    2

    Re:


    I'm still having problems with the $_SESSION code.
    I can't retrieve the info on the next page.

    After looking at the manual (which I think lacks enough examples / explanation) I came to this:

    <?php
    session_start();
    if (empty($_SESSION['count'])) {
    $_SESSION['count'] = 1;
    } else {
    $_SESSION['count']++;
    }
    ?>

    <html>
    <form enctype="multipart/form-data" method="POST" action="ads.php?<?php echo $_SESSION["count"]; ?>" />
    <input type="hidden" name="PHPSESSID" value="<?php echo $_SESSION["count"]; ?>" />
    Name:<input type="text" name ="name" /><br />
    Book:<input type="text" name ="book" /><br />
    Subject:<input type="text" name ="subject" /><br />
    Price (CAN):<input type="text" name ="price" /><br />
    Description: <br /><textarea cols="40" rows="5" name="description">
    </textarea><br />
    Click to upload:<input type="file" name="pix" /><br />
    <input type="submit" name="Upload" value="Upload Picture" />
    </form>
    </html>
    I managed to get the ID to send in a link to the other page.

    But on the next page, when I write:
    <?php
    echo $_SESSION['PHPDSESSID'];
    echo "<b>Name: </b>" . $_SESSION['name'] . "<br />";
    ?>

    How do I retrieve the info from the URL using $_SESSION? Also how do I generate the proper text from $_SESSION using the ID from the link.

    I'm open to anything you have in mind.
  16. #9
  17. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    Here is a very simple untested example:

    page1.php:
    PHP Code:
    <form action="page2.php" method="POST">
      <
    input type="text" name="first_name" />
    </
    form
    page2.php:
    PHP Code:
    <?php
      session_start
    ();
      
    $_SESSION['first_name'] = $_POST['first_name'];
    ?>
    <form action="page3.php" method="POST">
      <input type="text" name="last_name" />
    </form>
    page3.php:
    PHP Code:
    <?php 
      session_start
    ();
      echo 
    "Your name: " htmlspecialchars($_SESSION['first_name']) . ' ' htmlspecialchars($_POST['last_name']);
    This has the limitation of only allowing a particular user to be filling out one series of forms at a time. In order to overcome that, you would have to use the extra steps mentioned in post 4.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    40
    Rep Power
    2

    Re:


    Thanks for the answer.

    I got it working.

IMN logo majestic logo threadwatch logo seochat tools logo