简体   繁体   English

如何单击返回上一页并使用php或js重新加载以前发布的表单数据

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

I have a flow like this 我有这样的流程

  1. Order Form page (index.php) 订单表格页面(index.php)
  2. Confirmation page (where email is entered) (place-order.php) 确认页面(输入电子邮件的地方)(place-order.php)
  3. Success page (register.php) 成功页面(register.php)

All pages have the order form with display:none and can be called on click to display. 所有页面的订单都带有display:none,可以单击以显示。

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"); 现在,当我使用history.go(-1)或window.location.replace(“ place-order.php”); or 要么
window.history.back(); 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 window.location = url将不起作用,因为它将转到url,并且所有先前发布到该页面的表单数据都将丢失

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 ? 最好的方法是什么?

I realized that the answer is very simple using the _SESSION Variable ! 我意识到使用_SESSION变量,答案非常简单!

I stored the POST variable to SESSION['place-order'] variable and used 我将POST变量存储到SESSION ['place-order']变量中并使用了

 window.location:place-order.php 

in the register.php page to redirect and added the following code to the place-order.php page 在register.php页面中进行重定向,并将以下代码添加到place-order.php页面中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM