[PHP Code > PHP Step Form]

Step Form

Picture of me and my dog

This demo shows how to create a multi-step form using a hidden input step value for navigation. Please observe that each time you click the "Next" button the page refreshes. This means you are causing the page to reload and the contents shown are determined by the hidden value of the $step variable as it passes between pages via the $_POST array and then though a switch() statement.

This is "Page" One

Contents of page one. Etiam gothica laoreet nulla commodo liber. Me commodo amet liber quis vel. Gothica eleifend enim legentis typi tincidunt. Feugiat et et ullamcorper aliquam elit. Parum vel feugait feugait gothica tation.


Please note: I have NOT included HTML labels for input statements. This was done to simplify the code and concept. If you are going to create forms for your websites, then you should also use labels to identify the HTML controls for the disabled. Please review the demos provided -- these show lables for all input controls requiring user action.

You may use the following script as you need without any obligation to me whatsoever. However, a Donation via PayPal would be greatly appreciated -- please note, this site does not accept advertising.


Here's the PHP/HTML code for the Submit Button:

00 
07 <?php 08 09 error_reporting(E_ALL); // set error reporting to all 10 $self = htmlspecialchars(basename($_SERVER['SCRIPT_NAME'])); 11 12 $step = isset($_POST['step']) ? $_POST['step'] : 1; 13 14 ?> 15 16 16 <!doctype html> 16 <html lang="en-us"> 16 16 <head> 16 <meta charset="utf-8"> 16 <title>tedd's Examples</title> 16 </head> 16 16 <body> 17 34 <?php 35 switch($step) 36 { 37 case 1: // page 1 38 ?> 39 40 <h4>This is "Page" One</h4> 41 42 <p> 43 Contents of page one. Etiam gothica laoreet nulla commodo liber. Me commodo amet 44 liber quis vel. Gothica eleifend enim legentis typi tincidunt. Feugiat et et ullamcorper 45 aliquam elit. Parum vel feugait feugait gothica tation. 46 </p> 47 48 <form action="" method="POST" class="examples"> 49 <p> 50 <input type="hidden" name="step" value="2"> 51 <input type="submit" name="submit" value="Next"> 52 </p> 53 </form> 54 55 <?php 56 break; 57 58 case 2: // page 2 59 ?> 60 61 <h4>This is "Page" Two</h4> 62 63 <p> 64 Contents of page two. Processus consequat duis doming parum habent. Decima et 65 imperdiet humanitatis dolor Investigationes. Facilisi etiam lobortis consequat vel 66 videntur. 67 </p> 68 69 <form action="<?php echo($self); ?>" method="POST" class="examples"> 70 <p> 71 <input type="hidden" name="step" value="3"> 72 <input type="submit" name="submit" value="Next"> 73 </p> 74 </form> 75 76 <?php 77 break; 78 79 case 3: // page 3 80 ?> 81 82 <h4>This is "Page" Three</h4> 83 84 <p> 85 Contents of page three. Iriure iis est facit vero legentis. Seacula id usus saepius 86 notare vel. Ipsum tation claram aliquip decima cum. Lectores est facilisis est seacula 87 non. Gothica feugiat placerat aliquip autem imperdiet. 88 </p> 89 90 <form action="" method="POST" class="examples"> 91 <p> 92 <input type="hidden" name="step" value="1"> 93 <input type="submit" name="submit" value="Next"> 94 </p> 95 </form> 96 97 <?php 98 break; 99 } 100 ?> 101 102 102 </body> 102 </html>
  Show the above CODE for Copy/Paste below.

The following code will work "as-is" without any additional coding. However, remember to use a .php' suffix.


<?php error_reporting(E_ALL); // set error reporting to all $self = htmlspecialchars(basename($_SERVER['SCRIPT_NAME'])); $step = isset($_POST['step']) ? $_POST['step'] : 1; ?> <!doctype html> <html lang="en-us"> <head> <meta charset="utf-8"> <title>tedd's Examples</title> </head> <body> <?php switch($step) { case 1: // page 1 ?> <h4>This is "Page" One</h4> <p> Contents of page one. Etiam gothica laoreet nulla commodo liber. Me commodo amet liber quis vel. Gothica eleifend enim legentis typi tincidunt. Feugiat et et ullamcorper aliquam elit. Parum vel feugait feugait gothica tation. </p> <form action="" method="POST" class="examples"> <p> <input type="hidden" name="step" value="2"> <input type="submit" name="submit" value="Next"> </p> </form> <?php break; case 2: // page 2 ?> <h4>This is "Page" Two</h4> <p> Contents of page two. Processus consequat duis doming parum habent. Decima et imperdiet humanitatis dolor Investigationes. Facilisi etiam lobortis consequat vel videntur. </p> <form action="<?php echo($self); ?>" method="POST" class="examples"> <p> <input type="hidden" name="step" value="3"> <input type="submit" name="submit" value="Next"> </p> </form> <?php break; case 3: // page 3 ?> <h4>This is "Page" Three</h4> <p> Contents of page three. Iriure iis est facit vero legentis. Seacula id usus saepius notare vel. Ipsum tation claram aliquip decima cum. Lectores est facilisis est seacula non. Gothica feugiat placerat aliquip autem imperdiet. </p> <form action="" method="POST" class="examples"> <p> <input type="hidden" name="step" value="1"> <input type="submit" name="submit" value="Next"> </p> </form> <?php break; } ?> </body> </html>