...

View Full Version : php form question



ClubCosmic
03-29-2007, 12:18 AM
hi all,

I have a form using php. There are about 30 input fields. instead of having 1 page with a long form, i wanted to break it down into say 3 pages with 10 fields each using say a "next" link or button.

the field values in the first page wont pass to the next, even though i am not closing the form until all pages are complete. I'm not sure if this is possible but would like any ideas on how to do it.

tnx,
c.c.

rafiki
03-29-2007, 12:37 AM
look up sessions
http://uk2.php.net/manual/en/ref.session.php
store a variable in the session like so


session_start();
$_SESSION['field1'] = $_POST['field1'];
echo '<form..........>';

but you have to have session_start(); at the top of every page
which has the form on

sirborder
03-29-2007, 12:45 AM
Something else you could do is have different sections of the form on one page and let it do one part at a time. Then at the end you could do the MySQL insert part.

rafiki
03-29-2007, 12:48 AM
Something else you could do is have different sections of the form on one page and let it do one part at a time. Then at the end you could do the MySQL insert part.
sessions would be easier if you wanted to add all the fields into the same table
if you wanted one table for different parts of the form group them together in form and do it as sirborder said

ClubCosmic
03-29-2007, 02:23 AM
thanks for the replies

I never thought to use $_SESSIONS to do the task. DOH!:rolleyes:

tnx again,
c.c.

the-dream
03-29-2007, 09:11 PM
You could use hidden fields with the info from the the other pages dynamically put into the hidden fields!

Mabie?

aedrin
03-29-2007, 09:33 PM
That would be an unstable and unreliable solution.

ClubCosmic
03-30-2007, 10:34 PM
I have used:

session_name();
session_start();
at the beginning of the page.
i can echo a session variable after the first submit, yet I keep creating a new session every time the page refreshes.

for each "page" of the multiple page form, i am using <submit> and afterward placing the form vars in a session. and echoing the next form.

aedrin
03-30-2007, 11:04 PM
session_name();


You don't need this.

ClubCosmic
03-30-2007, 11:15 PM
i removed it. it still creates a new session. originally i didnt have session_name but tried it after reading around.

i have used session before without this happening.

aedrin
03-30-2007, 11:50 PM
I can't think of anything that could cause this, except that perhaps you are blocking the cookie that is required for this to work.

ClubCosmic
03-31-2007, 12:11 AM
i did figure this much out. if i link to another page before submitting the form on page 1, then it keeps the same session.

problem is,
i am using a switch statement to choose a function which is all on the same same so it keep making a new session every time the page refreshes.

should i refresh the page before session_start() ?

ClubCosmic
03-31-2007, 12:19 AM
the problem was the usually suspect.....ME!

i was using an if(isset($_POST[submit])) statement to determine whether or not to run the switch() statement.

not sure how this would cause that to happen but its working

thanks for the replies!!!

Fumigator
03-31-2007, 12:54 AM
I also find that my own stupidity is the root of all my problems :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum