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.
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]
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:
<?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.