Hey all, I'm trying to write a site where users enter info in several steps, using submit buttons on each page to go to the next page. Well, I want to give them the opportunity to use their "back" button to go back and edit their data, but when I try to go back all their form data is erased. Can I use PHP to display the data they entered before so they don't have to re-enter it? I think I can do it if I use a special "go back" link in the window but I want to be able to do it if they use the "back" button from their browser. Thanks.

    you can make a link to go "back" which simply passes all the form variables back to your last screen (through either one long URL link or a form), but then you'll also have to set up your form to reaccept existing values as default (. . . value=\"$name\">). It's not hard, but it does take time. Other the other hand, if you're not particulary concerned with security and having users enter their own varibles through the URL, you can just set each of your consecutive forms to mehod="GET" instead of POST -- this puts all your form results right in the URL, so the browser won't have any trouble remembering what the last page looked like. If you go with the GET method, you can also use javascript history tags to navigation backwards through your forms (<a href="javascipt:history.go(-1)"> -- or something like that . . .

    Cheers,
    Dan

      Thank you for your help, wiley. I didn't think about using GET instead of POST...that is a good idea for everything except the title (50 chars) and description (up to several thousand char.) fields. I'm not really concerned about security. Also, I noticed you used value=\"$name\", can you explain further what that does? I've seen it on these boards from time to time but haven't seen a description. Also, what do you think about submitting the data to a temporary database each time they click submit and then somehow...I don't know. I'm new at this. Thanks.

        If the goal is to get user data into a database eventually, it might make good sense to start inserting new input at the start of every screen. It won't save you any work when it comes to filling the form back in, though . . . if you decide to head this route, I would forget about "GET" and focus on making your "back" buttons more attractive than the browsers (if you always pull user data fresh from the database, you'll never run into confusion about what's in the database vs. what's on the screen).

        So, as far as the "value=" bit goes, this is something you put into each of your form fields to offer a default value in case there is one handy --

        If your data query went something like:
        $query = mysql_query("SELECT * FROM users WHERE id = '$id'");
        $data = mysql_fetch_array($query);

        then later your form fields might look like:

        <input type="text" name="name" value="$data[name]">

        (assuming you want both your variable called "$name" and you have a column named "name") -- if there's no value there, that shouldn't be a problem -- nothing appears as defualt in the form

        that's a little fragmented, sorry, but i think it should get you started --
        (hint: after the first INSERT statement, you might want to use mysql_insert_id_to retrive your new user's id, and you can pass that ahead to yourself to get the data back at the top of each form)

        hope that's helpful,
        dan

          i could be wrong but when u do a javascript back button, it keeps everything filled in except for password boxes..

          try something stupid like

          a href=javascript:history.go(-1)

          just a thought, seems easier than writing/reading from a temp sql db

            Hi. Thanks for your help everyone. To clear it up, wiley, i understand what value="$data[name]"> means, I was just wondering what the "/" did for it (i.e. value=\"$name\"> or if it did anything special to put them in.

              Sorry, sanders, didn't get the question -- the backslashes are relics of echo commands --

              i.e. in HTML it goes:
              <a href="index.php" . . .

              but if I'm writing PHP you have to escape out the quotes, so:
              echo "<a href=\"index.php\" . . .

              . . . as you're likely already familiar.

              Cheers,
              Dan

                Write a Reply...