Welcome to WebmasterWorld Guest from 54.162.167.40

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

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)

10+ Year Member



hi,
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'?

Pete

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

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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)

10+ Year Member



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

Example of one question


<form name="form1" method="post" action="">
<p>
<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>
<p/><p>
<select name="question2">
....
</form>

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)

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month




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;
}

Tom

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

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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
00000000000000000000

answered questions 6,9,15,16
00000300200000310000

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)

10+ Year Member



>using hidden fields won't work

Then what about sessions?

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

10+ Year Member



Yes sessions seem to do the trick,

here is a site i found useful

[curriculum.union.edu...]

pete

 

Featured Threads

Hot Threads This Week

Hot Threads This Month