开发者

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

开发者 https://www.devze.com 2022-12-21 05:27 出处:网络
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.

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


Use session.. Make sure you clear it when you are done saving the data.


when rendering the second form you could include all the fields from the previous form as hidden fields.

0

精彩评论

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