导航回第一个表单而不会丢失值 [英] navigating back to to first form without losing values

查看:62
本文介绍了导航回第一个表单而不会丢失值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在3个不同的页面上有3个表格.提交后,每个表单将转到下一个表单页面,如下所示:

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>

如果从form2.php和form3.php提交后的用户为form4.php, 我需要在每个页面中创建一个后退按钮,以便如果用户单击该按钮,则上一页仍会显示表单值(即使用户从最后一个表单返回到第一个表单) 我该如何实现?是使用会话变量或发布数据的唯一方法吗?

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?

推荐答案

会话将是IMO的最佳选择.在每个formX.php文件中,请确保启动会话:

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

$session_start(); 

然后在每个脚本的开头,检查$ _POST变量.如果您有任何内容(即从以前的表单提交的内容),请将其添加到$ _SESSION数组中.

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']); 

此外,在页面上呈现表单时,请为该文本字段使用$ _SESSION变量中的任何值.如果该字段为空或未设置,则将向用户显示一个空的文本框.

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!

这篇关于导航回第一个表单而不会丢失值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆