Create Multipage Form with hidden field in PHP
Description
The following code shows how to create Multipage Form with hidden field.
Example
Save the following code as page1.php
//page1.php// ww w . j a v a 2 s . c om
<html>
<body>
<div>
<form action="page2.php" method="post">
<p>Page 1 Data Collection:</p>
<input type="hidden" name="submitted" value="yes" />
Your Name: <input type="text" name="yourname" maxlength="150" /><br /><br />
<input type="submit" value="Submit" style="margin-top: 10px;" />
</form>
</div>
</body>
</html>
Save the following page as page2.php
//page2.php//w w w. j av a 2 s .c om
<html>
<body>
<div>
<form action="page3.php" method="post">
<p>Page 2 Data Collection:</p>
Selection:
<select name="yourselection">
<option value="nogo">make a selection...</option>
<option value="1">Choice 1</option>
<option value="2">Choice 2</option>
<option value="3">Choice 3</option>
</select>
<input type="hidden" name="yourname" .
value="<?php echo $_POST['yourname']; ?>" />
<input type="submit" value="Submit" style="margin-top: 10px;" />
</form>
</div>
</body>
</html>
Save the following page as page3.php
//page3.php// w w w .j a va 2 s .c o m
<html>
<body>
<form action="page4.php" method="post">
<p>Page 3 Data Collection:</p>
Your Email: <input type="text" name="youremail" maxlength="150" /><br />
<input type="hidden" name="yourname".
value="<?php echo $_POST['yourname']; ?>" />
<input type="hidden" name="yourselection".
value="<?php echo _POST['yourselection']; ?>" />
<input type="submit" value="Submit"/>
</form>
</body>
</html>
Save the following code as page4.php
//page4.php/*from ww w . j a va 2s . co m*/
<html>
<body>
<?php
echo "Your Name: " . $_POST['yourname'] . "<br />";
echo "Your Selection: " . $_POST['yourselection'] . "<br />";
echo "Your Email: " . $_POST['youremail'] . "<br />";
?>
<a href="page1.php">Try Again</a>
</body>
</html>