简体   繁体   中英

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.

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'. 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.

Thank you SO. :)

You need sessions. Sessions store an ID on the computer, (sometimes in a cookie) that references information on the server. 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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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