tags:

views:

54

answers:

3

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. :)

A: 

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

Broken Link
Can you provide a bit more information; why should I use session?
Serg
http://www.tizag.com/phpT/phpsessions.php take a look at this.. Might help you..
Broken Link
A: 

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

emh
So every time you want to add a field to a page you would, potentially, have to add it to all the other subsequent pages as well. While it would get the job done I wouldn't recommend it.
Mike B
it could be handled with a simple loop. no need to change it when you add a new field to the previous form.
emh
+2  A: 

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

Jonah Bron