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

PHP Server Side Scripting Forum

Html PHP multipage form
Need help with multipage form and redirection

5+ Year Member

Msg#: 3593076 posted 3:54 pm on Mar 6, 2008 (gmt 0)


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

Living circumstances:

The Living circumstances field is a dropdown consisting of values:

Own Outright

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.




5+ Year Member

Msg#: 3593076 posted 5:11 pm on Mar 6, 2008 (gmt 0)

The variables from your form get carried to the script you've put in it's action="", and by specifying either method="post" or "get". Then on the script specified in action="", you can get the variables by doing $_GET["variable_name"] and $_POST["variable_name"]. In the form on that page, you should have a php script that uses the variables from $_GET or $_POST to do the <input type="hidden" name="name_of_the_hidden_field" value="value_of_the_hidden_field" /> which should be outputed in a form, and when the form gets submit, they would be sent like if they were textboxes or any other object, except users won't see them.

[edited by: Vis3R at 5:12 pm (utc) on Mar. 6, 2008]


5+ Year Member

Msg#: 3593076 posted 5:12 pm on Mar 6, 2008 (gmt 0)

hey Tony,
heres something i just cooked up.

function redirect(form){
var page = form.living.options[form.living.options.selectedIndex].value;
self.location = "morgage-form.php";
else if (page==2){
self.location = "own-form.php";
else if (page==3){
self.location = "renting-form.php";
<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>
<input type="button" value="submit" onclick="redirect(this.form);">

As you can see it changes on two events: when the box is changed (onchange) or when the button is clicked (onclick). pretty simply javascript stuff. feel free to remove the js events to your liking.


5+ Year Member

Msg#: 3593076 posted 5:32 pm on Mar 6, 2008 (gmt 0)

There are lots of different ways to do this, but I think I would choose sessions if I were doing it myself.

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:

// Start the session

// 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

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.

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