Is there a way to provide a link that would allow someone that filled out a form to go back without losing their data instead of having to use the browser back button? What I have is a membership form (add_member.php). When user hits submit, it is posted to process_member.php. My process_member.php first returns to the browser the contents of the filled in form for the user to check to ensure that they entered the correct information before the process_member.php script enters the data into a database. The script works fine and this is not where my problem lies. I just want to provide a link to go back to the cached form to allow any changes before the script processes the data. I tried <a href="<? $_SERVER['HTTP_REFERER'] ?>">BACK TO FORM</a> but all the form fields are no longer filled in.

I just want to add the link because I think that would look more professional than making the user hit the back button.

    you could use javascript possibly, though I am not sure if it would keep the form filled in:

    make a link like: <a href="javascript:history.go(-1);">Back</a>

    or you could use a form and submit button called Back, and post all of the variables back to that page, you would need a form handling script on that page that would detect your "Back" submit and fill the fields with the appropriate variables.

    Brad

      You can use header() function with your form elements in it.

      <?php
      if (empty($field1) || empty($field2) || empty($field3)) {
      	header("Location: add_member.php?field1=$field1&field2=$field2&field3=$field3&back=1");
      } else {
      	// process data
      }
      ?>
      
      Form examples:
      
      <?php
      if ($back == 1) { echo "<font color=\"red\"><b>Fields with astrics ( * ) are required</b></font>\n"; }
      echo "<form action=\"process_member.php\" method=\"post\">\n";
      echo "<input type=\"text\" name=\"field1\" value=\"$field1\"> *<br>\n";
      echo "<input type=\"text\" name=\"field2\" value=\"$field2\"> *<br>\n";
      echo "<input type=\"text\" name=\"field3\" value=\"$field3\"> *<br>\n";
      echo "</form>\n";
      ?>

        If all you want to do is emulate the Back button in the browser, then Boo has it right... use the history.back() or history.go(-1) Javascript method. You can do this with an HTML link or a button.

        However, I rarely do this. Anyone using a browser should be familiar with the Back button. They can also simply hit Backspace or Alt-Left Arrow.

        If you want to create a preview page, with the option of re-editing information, I recommend first storing the data in a temporary db table, then opening up the original form and populating it with that temporary data. This will take care of bizarre situations such as computer lockups or power outages. Once their computer is back online, they can resume where they left off, rather than starting all over again.

          Write a Reply...