Saturday 6 April 2024

Multi page form in PHP with Example

A multi page form in PHP are used to retain values of a form and can transfer them from one page to another . 

multipage.php

<html>

<body>

<div style="width: 500px; text-align: left;">

<form action="multipage2.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>

OUTPUT







 multipage2.php

<html><body>

<div style="width: 500px; text-align: left;">

<form action="multipage3.php" method="post">

<p>Page 2 Data Collection:</p>

Selection:

<select name="yourselection">

<option value="nogo">make a selection...</option>

<option value="Choice1">Choice1</option>

<option value="Choice2">Choice2</option>

<option value="Choice3">Choice3</option>

</select><br /><br />

<input type="hidden" name="yourname" value="<?php echo $_POST['yourname']; ?>" />

<input type="submit" value="Submit" style="margin-top: 10px;" />

</form>

</div>

</body></html>

OUTPUT






multipage3.php

<html>

<body>

<div style="width: 500px; text-align: left;">

<form action="multipage4.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" style="margin-top: 10px;" />

</form>

</div>

</body>

</html>

OUTPUT






multipage4.php


<html>

<head><title>Page 4</title></head>

<body><div style="width: 500px; text-align: left;">

<?php

//Display the results.

echo "Your Name: " . $_POST['yourname'] . "<br />";

echo "Your Selection: " . $_POST['yourselection'] . "<br />";

echo "Your Email: " . $_POST['youremail'] . "<br />";

?>

<a href="multipage.php">Try Again</a>

</div></body></html>

OUTPUT



No comments:

Post a Comment