homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Creating a multipage form with php
How do I create a multipage form (using a cookie)?

 6:47 pm on Oct 5, 2002 (gmt 0)

I have a little knowledge of PHP since I picked up a book recently but have not got to grips with it yet.

I would like to create a form that uses about 42 drop-down boxes. There are 7 sections which these 'questions' can be broken down into.
(6 q's per section)

I would like to create a page (or a number of pages) that a user can fill in some content (i.e. select some boxes) and then go away an come back to the page with the content restored.

The 7 sections do not have to be filled in any particular order so I would be happy for the form to be broken into a number of pages. In fact this would be the best thing as the 'user' may wish to fill out my form in their own order.

I would like to be able to collect all the data (stored in a cookie?s?) they have entered an pass that to another php page that does some adding up of etc.

Can anyone can suggest a way to achieve this?

One idea was to use a cookie(s)? but how do I create get all these pages to set to the same cookie? and have each page use a 'save so far' button?
Then how do I get the final page to collect all the info and pass it to the 'wizzy script'?




 3:32 am on Oct 6, 2002 (gmt 0)

Welcome to WebmasterWorld [webmasterworld.com] raingerpete

As far as I see it you have a couple of options. I assume there is no login so you can't track everything on your side.

42 questions? You could put the answers into the cookie. A 42 char/int string that you can access and know how far along they are and what their answers were.

You could use the index from the drop down. If there are 6 items you could put numbers between 0 and 5 or 1 and 6, whatever you like.

When they are done you can change the cookie to say finished or something.


 1:49 pm on Oct 6, 2002 (gmt 0)

The 42 questions are in the form of drop-down boxes :

Example of one question

<form name="form1" method="post" action="">
<select name="question1">
<option selected>Please select</option>
<option value="0">value zero</option>
<option value="1">value one</option>
<option value="2">value two</option>
<option value="3">value three</option>
<select name="question2">

But there are 6 questions of this form on each 'page'.

I would like the user to be able to go through the 7 pages in any order they wish so using hidden fields won't work ( i think ).

How do I save all the info to the same cookie?


 5:11 pm on Oct 6, 2002 (gmt 0)

I would like the user to be able to go through the 7 pages in any order

That throws out jatar_k's solution I think, since it depends on string always having the same order.

using hidden fields won't work

Actually, it works just fine. Let's say you have

<option value="0" selected>Please select</option>
<option value="1">option 1</option>
<option value="2">option 2</option>

So if the person either doesn't answer the question or hasn't visited that page, the option is set to zero

if ($HTTP_POST_VARS['quest1']) {
This question has been answered, so do stuff;
} else {

This question hasn't been answered;



 6:10 pm on Oct 6, 2002 (gmt 0)

I was thinking along the lines of the cookie looking like this. Based on 20 questions, 1-4 for each answer and 0=not answered.

no answers

answered questions 6,9,15,16

as you can see, the cookie knows whats up. On loading the page it reads the cookie and sets the questions accordingly. Then when they submit the page it updates the cookie.


 8:13 pm on Oct 6, 2002 (gmt 0)

>using hidden fields won't work

Then what about sessions?


 12:50 pm on Oct 7, 2002 (gmt 0)

Yes sessions seem to do the trick,

here is a site i found useful



Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved