简体   繁体   English

您如何建议我将数据从一种形式传递到另一种形式,最后传递到另一个最终页面?

[英]How do you recommend I pass data from one form to another, and finally to another final page?

I'm taking a class in PHP and I'm a real newbie when it comes to best practices and whatnot. 我正在用PHP上课,并且在最佳实践方面我是一个真正的新手。

I have a little homework that the teachers wants me to hand in. 我有一些功课,老师要我交。

  1. Create a form that asks a user for his name, last name, age and birthday. 创建一个表单,询问用户姓名,姓氏,年龄和生日。

  2. When the users clicks submit, take him to the second form and ask for his location, nationality and religion. 当用户单击提交时,将他带到第二个表单并询问他的位置,国籍和宗教信仰。

  3. Finally when he submits that , take him to a 'thank you' page showing all the written information he input previously. 最后,当他提交该信息时 ,将其带到“谢谢”页面,其中显示了他先前输入的所有书面信息。

I'm thinking about using GET to pass things along, but I've only done this with one form to another, not multiple 'hops'. 我正在考虑使用GET传递信息,但我只是通过一种形式将其传递给另一种形式,而不是多次“跳跃”。 Would this work? 这行得通吗?

What other way do you think I should do this? 您认为我还应该采取其他哪种方式? I'm not sure if this should be community wiki because I'm sure there's a perfect answer, but please let me know and I'll change it. 我不确定这是否应该是社区Wiki,因为我确定有一个完美的答案,但是请告诉我,我将对其进行更改。

Thank you SO. 谢谢你这么。 :) :)

You need sessions. 您需要会议。 Sessions store an ID on the computer, (sometimes in a cookie) that references information on the server. 会话在计算机上(有时在cookie中)存储一个ID,该ID引用服务器上的信息。 You just create a session, and then you can put whatever data you want in it. 您只需创建一个会话,然后就可以将所需的任何数据放入其中。 Just grab that data on another page whenever you want. 只要您愿意,就可以在另一页上获取这些数据。

page 1 第1页

session_start(); // start session
$_SESSION['name'] = 'Jimmy'; // put something into the session

And on the next page... 然后在下一页...

echo $_SESSION['name']; // echos "Jimmy"
session_destroy(); // don't want the session anymore

More info at http://w3schools.com/php/php_sessions.asp 有关更多信息, 请访问http://w3schools.com/php/php_sessions.asp

使用会话。确保在完成数据保存后将其清除。

呈现第二个表单时,您可以将前一个表单中的所有字段都包含为隐藏字段。

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

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