Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you make the browser re-post form data when using the back button?
    primarykey
    data
    text
    <p>I guess my question is in understanding the $_POST handling.</p> <p>So I have two pages that handle 2 forms. Page 1 asks for some information that will be used in page 2. When submitted the form action uses the same page then redirects to next page upon validation, but only handles the data when <strong>$_GET</strong> variable <strong>?usersubmit=1</strong>. </p> <pre><code>&lt;form action="&lt;?=$_SERVER['PHP_SELF']?&gt;?usersubmit=1" method="post" name="form1"&gt; &lt;input type="text" name="field1"&gt; &lt;/form&gt; </code></pre> <p>So say I have page called form1.php. Upon submit its sent to form1.php?usersubmit=1. The page now assigns the posted data to session variables and then redirects to form2.php via header('location:form2.php').</p> <pre><code>&lt;? if($_GET['usersubmit']){ if($_POST['field1']){ #if valid then assign session variable and redirect to next form $_SESSION['field1'] = $_POST['field1']; header("location:form2.php"); }else{ #if invalid send error message $error = true; } } ?&gt; </code></pre> <p>My problem is in when users hit the 'back' button on their browser to edit data from a previous form. The browser doesnt re-post this data it just shows them a blank form. I'd prefer not to use $_SESSION data to fill out the forms because I suspect the re-post method may be a quicker and less problematic fix. </p> <p>I also tried a javascript redirect instead of a header but browsers are smart enough to not send you back to a page that wants to redirect you so it doesnt work.</p> <p>any help in understanding this would be greatly appreciated. thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload