Forum Moderators: coopster
I wonder if any of your gurus could help me.
I'm trying to set up a multipage form
The first page consists of 3 fields
Name:
Age:
Living circumstances:
The Living circumstances field is a dropdown consisting of values:
Morgage
Own Outright
Renting
What I would like to do is: If the user selects one of the options from the Living circumstances after pressing the submit button it takes them to a form based on their living circustances. I.e User selects 'Renting' they get redirected to a page called renting-form.php. What I would also like is the information entered into the fields Name and age as Living circumstances get carried over to the selected form page, so they can be added along with the details entered on the new form . I've been reading about hidden fields but have had no success, can someone show me a brief example of how I may do the above.
Thank you in advance.
Tony
[edited by: Vis3R at 5:12 pm (utc) on Mar. 6, 2008]
<html>
<head>
<script>
function redirect(form){
try{
var page = form.living.options[form.living.options.selectedIndex].value;
if(page==1){
self.location = "morgage-form.php";
}
else if (page==2){
self.location = "own-form.php";
}
else if (page==3){
self.location = "renting-form.php";
}
}
catch(e){}
}
</script>
</head>
<body>
<form name="form" action="action.php" method="POST">
Name:<input type="text" name="Name"><br>
Age:<input type="text" name="Age"><br>
Living Circumstance:
<select name="living" onchange="redirect(this.form);">
<option selected value="-1">Select a condition</option>
<option value="1">Morgage</option>
<option value="2">Own</option>
<option value="3">Renting</option>
</select>
<input type="button" value="submit" onclick="redirect(this.form);">
</form>
</body>
</html>
Have the first page form submit to a small processing page that will put all of your form information into a session, then do a header redirect to the page you want according to their selection. The processing page might look like so:
<?php
// Start the session
session_start();
// Fill it with our post vars
$_SESSION['name'] = $_POST['name'];
$_SESSION['age'] = $_POST['age'];
$_SESSION['living'] = $_POST['living'];
// Check the living var and redirect accordingly
if($_POST['living'] == 'mortgage')
header('Location: mortgage.php');
elseif($_POST['living'] == 'own')
header('Location: own.php'):
elseif($_POST['living'] == 'rent')
header('Location: rent.php');
// Just in case someone got here without the form
else
header('Location:default.php');
?>
Then as the user fills out each stage of the form, have the information on each page go into the session. At the end, you can pull all of the cumulative information from the session and do whatever you like with it.