...

View Full Version : Move to next page on a form



dtw
11-20-2006, 07:25 PM
I am making my first attempt at writing html and using php. I have created a simple page with tables and radio buttons as the beginning of a web-based survey.

How do I use a button to move the user to the next page of the survey, rather than submitting the form and then exiting the survey?

mlseim
11-20-2006, 07:39 PM
Your form will call the next page, which is another form ...
all of your pages have the extension .php (instead of .html) ...

At the beginning of the next page, put something like this at
the very top of your script. It grabs all of the variables from
your first form ... note, you'll actually use variable names from
your form (this is just an example):

<?php
$name=$_REQUEST['name'];
$phone=$_REQUEST['phone'];
$email=$_REQUEST['email'];
?>

Then proceed with your HTML for the next form.

Continue on to the next page with the next set of variables
from the current form. Do not duplicate any variable names.

Once you get to your last form, it will call the PHP script that
sends the email. At the top of that script, you will grab the last
variables you need (from the last form).

Now, all of those variables you've grabbed on each page are saved,
because they are all global. You can then build your email using any
of them and mail it out.

I hope that makes sense ... it's hard to put into words.

dtw
11-20-2006, 07:57 PM
1) OK, so at the bottom of page 1 I will have something like "action" submit data and move to http://myserver/surveys/initialsurvey_2.php to take me to the next page?

After moving from each page of the form will I need to grab each of the variable names used in all of the previous pages and put them into the new page? That seems a bit cumbersome. I will be using a mysql db to gather the data, so perhaps the email comment is not relevant to my case.

2) Would this mean that I can just capture (post) the data to the db page by page into one cumulative table?

dtw
11-20-2006, 08:22 PM
OK, allow me to help you help me :)

Below is what I've titled insert.php. As you can see, it inserts data from the form into the db.



$first=$_POST['first'];
$last=$_POST['last'];
$phone=$_POST['phone'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$email=$_POST['email'];
$web=$_POST['web'];

mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO contacts VALUES (null,'$first','$last','$phone','$mobile','$fax','$email','$web')";


$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
else
{
echo 'Data has been input into the database';
}
mysql_close();
?>


The line "Data has been input into the database" is returned if everything worked. So, I'm guessing that I can insert something different that says the php equivalent of "Go to page two of survey located at http://url/page_2.php".

Is this how I would proceed? And if so (or if not), how would I say this in php?

Also, do you know of any good freeware programs that will help me automatically create multi-page surveys and then let me tinker with the scripts? I have access to dreamweaver, but can't see how to get it to create forms with multiple pages.

Thanks for your help.

mlseim
11-20-2006, 08:52 PM
If you can use the next script to put the previous scripts (form) data
into MySQL, that would be the best thing. Then, when they return at
a later time, the data would be there up to the point where they ended.

In your example, your next form could be on that page "insert.php", right
after it put the data in from the first form.

remember that you can mix PHP and HTML, so at the top of each page
where you have your form, you have the PHP that puts the data into
the MySQL from the previous form. Then you display the next form right
in the same page.

So yes, you have the correct idea ...

Display a form.... submit goes to the next page.
that page saves the previous form in MySQL and immediately
displays the next form.

The only tricky part would be to make sure they either came from the
previous form, or are continuing on from a previous session. There must
be something not showing in your example where they are logged-in, so
the survey knows who they are?

That part I don't see ...

If they are anonymous users, you will need to add a field to your MySQL
with some kind of code. That code is saved as a cookie on their PC.
Somehow, you need to see if they are continuing the survey at a later time
by matching their cookie to an entry in your MySQL. see what I mean?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum