开发者

Php form across multiple pages need to prepopulate if user goes backwards

开发者 https://www.devze.com 2023-01-27 16:03 出处:网络
Heres the situation: I have a form that is spread across three pages. (Page A, Page B, Page C). User starts at A and fills out the form clicks button that goes to page B

Heres the situation: I have a form that is spread across three pages. (Page A, Page B, Page C). User starts at A and fills out the form clicks button that goes to page B

    foreach($_POST as $key => $val){
    $_SESSION[$key]  = $val;
    }   

I use above to send form results to a session. Now user can do either fill out page B and click to advance to Page C or Click to go "back" to page A. If user goes back to A I want all the fields populated.

   开发者_高级运维         $Email = $_GET['preview'] ? $_SESSION['Email'] : $_POST['Email'];

I several of these above to pre - populate the form.

Ok here's the problem. If user goes A --> B --> C and then wants to go back to B I lose all of A's session variables. And obviously is user then goes back to a none A's fields have data.

Any help at all would be great.


do a redirect after a POST, so the brouwser won't repost

if($_SERVER['REQUEST_METHOD'] == 'POST') {
  header('Location: '.$_SERVER['REQUEST_URI']);
}

this stops the question about resending post data(page out of date) when navigating with history

0

精彩评论

暂无评论...
验证码 换一张
取 消