| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Rock it out.
Join Date: Dec 2007
Posts: 209
|
I like keeping everyone on their toes, so I found another exciting thing to do that I don't know how to do! And, as have been on all my other threads, this one is yet again on the subject of forms. While I am learning more and faster (I'm mid some intensive study of PHP), I have not yet come across any way to stretch forms out over more than one page. I'm making a form currently that I want to carry on over three pages (and don't worry, it's not a page-long form for each page, and people will not blow it off due to length). This'll hopefully be my last post in the "help me!" forum, and I'll start being a helpER. |
|
|
|
|
|
#2 (permalink) |
|
Spare Parts
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 5,092
|
You can either do it with a session variable or by storing the previous results in hidden fields in the next pages form. <input name="fromlastpage1" type="hidden" id="fromlastpage1" value="<?php echo $fromlastpage1; ?>"> <input name="fromlastpage2" type="hidden" id="fromlastpage2" value="<?php echo $fromlastpage2; ?>"> <input name="fromlastpage2" type="hidden" id="fromlastpage3" value="<?php echo $fromlastpage3; ?>"> |
|
|
|
#4 (permalink) |
|
Spare Parts
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 5,092
|
You Submit the first form1 and make its target form2. In form2 you have to catch and hold in the hidden fields the values from the first form1. When you Submit form2 the new data and the data from form1 are all passed on. You could send them to form3 if needs be, you would need to set up hidden fields to collect all the previous data. |
|
|
|
#5 (permalink) |
|
Rock it out.
Join Date: Dec 2007
Posts: 209
|
So if I wanted to make a 3-page form, I'd set up hidden fields on page 2 to catch the data from page 1, and then hidden fields on page three for both page one and page two? Or could I put the hidden fields in page three to catch the data from page two, and the data in the hidden fields on page two? Forgive the large # of questions |
|
|
|
#6 (permalink) | |
|
Senior Member
Join Date: Jan 2005
Posts: 12,340
|
Quote:
Page 1. input "Name" Page 2. input "Gender" hidden "Name" Page 3. input "Age" hidden "Name" hidden "Gender" Finally, process the form. $_POST['name'], $_POST['gender'], $_POST['age'] |
|
|
|
|
#7 (permalink) | |
|
Senior Member
Join Date: Jan 2005
Posts: 12,340
|
Quote:
Page 1. input "Name" Page 2. input "Gender" hidden "Name" Page 3. input "Age" hidden "Name" hidden "Gender" Finally, process the form. |
|
|
|
|
#9 (permalink) |
|
shiro
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 3,066
|
One thing to be careful of is that hidden fields are visible in the source code. They are only hidden in the display. So if its any kind of secure info (password etc) you definitely want to use a session variable rather than a hidden field. |
|
|
|
#10 (permalink) |
|
Spare Parts
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 5,092
|
Yes Haku, you are right to point that out. I was trying to keep it at a beginner level. Session variables would definately be the better way to do this. And easier too. Listen to Haku! |
|
|
|
#12 (permalink) |
|
shiro
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 3,066
|
PHP Tutorial - Session They are an essential part of good programming! Basically a cookie, but more secure, as the data cannot be seen by the user, whereas the data in a cookie can be seen by the user. That being said, they are apparently also one of the first thing hackers attack when trying to hack a site. |
|
|
|
#13 (permalink) |
|
Senior Member
Join Date: Jan 2005
Posts: 12,340
|
Also you don't want to store passwords in a session variable. Passwords should only be used to query against the database and many things I've read have said, ideally, nothing should be stored in sessions except a unique identifier. |
|
|
|
#16 (permalink) | |
|
Rock it out.
Join Date: Dec 2007
Posts: 209
|
Quote:
Is this just as simple as assigning the "action" of the page 1 form the url of the page 2 form? Or did I just make myself look like a total imbicil? |
|
|
|
|
#17 (permalink) |
|
Everything is fine.
|
Depending on how big/complicated your form is, you can go either way. As mentioned previously, anything of a secure-ish nature should be done with Sessions for better security. Also when you are doing large forms the code you end up with on the last page becomes monstrously big and can be a nightmare to keep your cool with - the less data held on the page will increase it's speed/download for the user (but this generally is the case with *huge* forms). For small and non-trivial forms you might be better off using the hidden field method. You may also want to go one step further (depending on the nature of your form data) and store the info in to a MySQL Database. But that's another lesson altogether. I would advise you to try both because at some stage in your development life you'll end up needing to use Sessions to track form input, so it would be good to get to grips with it as early as possible. - Mike |
|
|
|
#18 (permalink) | |
|
Senior Member
Join Date: Jan 2005
Posts: 12,340
|
Quote:
Security: hidden inputs < flat-file storage < sessions < database I put flat file as more secure than hidden inputs because you do get some degree of "security through obscurity". |
|
|
|
|
#19 (permalink) |
|
Rock it out.
Join Date: Dec 2007
Posts: 209
|
What I'm making is a pretty butt-simple form. I'm learning PHP but I need to get this site up ASAP, so I'm looking more for the quick and dirty and then when I'm through actually learning some good stuff I can come back and doctor it up. Thankfully my client is a family member, so I can get away with that I'm just trying to get it to WORK first. |
|
|
|
#20 (permalink) | |
|
Rock it out.
Join Date: Dec 2007
Posts: 209
|
Quote:
By this do you mean that I have to set the "action" point to the url of the next page? I really hate to sound like a dumb git, but that's kinda where I stand |
|
|
![]() |