how to go back to previous page on click and reload with previously posted form data with php or js

1.8k views Asked by At

I have a flow like this

  1. Order Form page (index.php)
  2. Confirmation page (where email is entered) (place-order.php)
  3. Success page (register.php)

All pages have the order form with display:none and can be called on click to display.

In the success page, if the email is empty, it says 'go back and retry'.

Now when I use history.go(-1) or window.location.replace("place-order.php"); or
window.history.back(); it goes to the previous page. But the browser asks the user to reload page as the webpage has expired.

window.location=url will not work as it will go the url and all previously posted form data to that page will be lost

I want the browser to go back to the page and automatically refresh the page without the browser asking you to do it retaining the form values as when passed on from order form

What would be the best approach ?

1

There are 1 answers

0
user3526204 On BEST ANSWER

I realized that the answer is very simple using the _SESSION Variable !

I stored the POST variable to SESSION['place-order'] variable and used

 window.location:place-order.php 

in the register.php page to redirect and added the following code to the place-order.php page

if(isset($_POST['clothessub']) || $_SESSION['placeorder']){
    if(empty($_POST)){$_POST=$_SESSION['placeorder'];}  
    //Do my stuff
}