navigating back to to first form without losing va

2019-07-28 04:16发布

I have a 3 forms on 3 different pages. Each form upon submit will go to the next form page as follows:

<form action="/form2.php" method="post>
<input type="submit" name"next" value="next">
</form>
<form action="/form3.php" method="post>
<input type="submit" name"next" value="next">
</form>

<form action="/form4.php" method="post>
<input type="submit" name"next" value="next">
</form>

If the user as at form4.php after submission from form2.php and form3.php, I need to create a back button in each page such that if a user clicks on the button the previous page still displays the form values(Even the user goes back from last form to first form) How do I acheive it? Is using session variables or post data only way to do it?

标签: php forms
2条回答
贪生不怕死
2楼-- · 2019-07-28 04:59

You could serialize the data and write it to a file, or save each section to the db.

查看更多
贼婆χ
3楼-- · 2019-07-28 05:08

Sessions would be your best option IMO. In each formX.php file, be sure to start the session:

$session_start(); 

And then at the beginning of each script, check for $_POST variables. If you have any (i.e submitted from previous form) add them to the $_SESSION array.

$_SESSION['lastname'] = $_POST['lastname']); 

In addition, when rendering the form on the page, use whatever value is in the $_SESSION variable for that text field. If it is empty or not set, then the user will be presented with an empty textbox.

[SECURITY DISCLAIMER] I should warn you that haplessly taking user input and throwing around in your code is a recipe for security disasters. Make sure you filter input and escape output when doing all of this!

查看更多
登录 后发表回答