Old 19-12-2007, 14:10   #1 (permalink)
Kaklz
Rock it out.
 
Kaklz's Avatar
 
Join Date: Dec 2007
Posts: 209
Ok, one more...

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.
  Reply With Quote
Old 19-12-2007, 14:40   #2 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
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; ?>">
__________________
  Reply With Quote
Old 19-12-2007, 14:43   #3 (permalink)
Kaklz
Rock it out.
 
Kaklz's Avatar
 
Join Date: Dec 2007
Posts: 209
Oh. That's easy.
One thing - how would I prevent the "submit" button from submitting? Just don't include it?
  Reply With Quote
Old 19-12-2007, 14:58   #4 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
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.
__________________
  Reply With Quote
Old 19-12-2007, 15:06   #5 (permalink)
Kaklz
Rock it out.
 
Kaklz's Avatar
 
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
  Reply With Quote
Old 19-12-2007, 15:22   #6 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
Quote:
Originally Posted by Kaklz
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?
This.

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']
  Reply With Quote
Old 19-12-2007, 15:23   #7 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
Quote:
Originally Posted by Kaklz
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?
This.

Page 1.

input "Name"

Page 2.

input "Gender"
hidden "Name"

Page 3.

input "Age"
hidden "Name"
hidden "Gender"

Finally, process the form.
  Reply With Quote
Old 19-12-2007, 15:25   #8 (permalink)
Kaklz
Rock it out.
 
Kaklz's Avatar
 
Join Date: Dec 2007
Posts: 209
Ah hah. Thanks again, pgo.
  Reply With Quote
Old 19-12-2007, 19:42   #9 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
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.
  Reply With Quote
Old 19-12-2007, 19:46   #10 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
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!
__________________
  Reply With Quote
Old 19-12-2007, 21:02   #11 (permalink)
Kaklz
Rock it out.
 
Kaklz's Avatar
 
Join Date: Dec 2007
Posts: 209
Forgive the totally newbie question, but what are session variables?
  Reply With Quote
Old 19-12-2007, 21:03   #12 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
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.
  Reply With Quote
Old 19-12-2007, 21:24   #13 (permalink)
pgo
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.
  Reply With Quote
Old 20-12-2007, 13:35   #14 (permalink)
Kaklz
Rock it out.
 
Kaklz's Avatar
 
Join Date: Dec 2007
Posts: 209
Thanks, all. Question: will setting up hidden fields to catch the data work on data in Radio buttons?
  Reply With Quote
Old 20-12-2007, 13:47   #15 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
It'll work for any form field value.
  Reply With Quote
Old 20-12-2007, 13:50   #16 (permalink)
Kaklz
Rock it out.
 
Kaklz's Avatar
 
Join Date: Dec 2007
Posts: 209
Quote:
Originally Posted by datahound
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.

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?
  Reply With Quote
Old 20-12-2007, 13:56   #17 (permalink)
MikeMackay
Everything is fine.
 
MikeMackay's Avatar
 
Join Date: Feb 2005
Location: Witham & London
Posts: 900
Send a message via MSN to MikeMackay Send a message via Skype™ to MikeMackay
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
  Reply With Quote
Old 20-12-2007, 14:00   #18 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
Quote:
Originally Posted by MikeMackay
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
Definitely, but it should be mentioned that storing the process data in a database is more secure than sessions.

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".
  Reply With Quote
Old 20-12-2007, 14:10   #19 (permalink)
Kaklz
Rock it out.
 
Kaklz's Avatar
 
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.
  Reply With Quote
Old 20-12-2007, 16:52   #20 (permalink)
Kaklz
Rock it out.
 
Kaklz's Avatar
 
Join Date: Dec 2007
Posts: 209
Quote:
Originally Posted by datahound
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.

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
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8