[PHP Code > PHP Submit Form]

Submit Button Form

Picture of me and my dog

This demo shows how to create a multi-step form using simple Submit Buttons for Navigation. Please observe that each time you click a Submit Button the page refreshes. This means you are causing the page to reload and the contents shown are determined by the value of the Submit Button 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 $submit = isset($_POST['submit']) ? $_POST['submit'] : 'Go To Page 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 35 <?php 36 switch($submit) 37 { 38 case 'Go To Page 1': // page 1 39 ?> 40 41 <h4>This is "Page" One</h4> 42 43 <p> 44 Contents of page one. Etiam gothica laoreet nulla commodo liber. Me commodo amet 45 liber quis vel. Gothica eleifend enim legentis typi tincidunt. Feugiat et et ullamcorper 46 aliquam elit. Parum vel feugait feugait gothica tation. 47 </p> 48 49 <form action="" method="POST" class="examples"> 50 <p> 51 <input type="submit" name="submit" value="Go To Page 2"> 52 <input type="submit" name="submit" value="Go To Page 3"> 53 </p> 54 </form> 55 56 <?php 57 break; 58 59 case 'Go To Page 2': // page 2 60 ?> 61 62 <h4>This is "Page" Two</h4> 63 64 <p> 65 Contents of page two. Processus consequat duis doming parum habent. Decima et 66 imperdiet humanitatis dolor Investigationes. Facilisi etiam lobortis consequat vel 67 videntur. 68 </p> 69 70 <form action="<?php echo($self); ?>" method="POST" class="examples"> 71 <p> 72 <input type="submit" name="submit" value="Go To Page 3"> 73 <input type="submit" name="submit" value="Go To Page 1"> 74 </p> 75 </form> 76 77 <?php 78 break; 79 80 case 'Go To Page 3': // page 3 81 ?> 82 83 <h4>This is "Page" Three</h4> 84 85 <p> 86 Contents of page three. Iriure iis est facit vero legentis. Seacula id usus saepius 87 notare vel. Ipsum tation claram aliquip decima cum. Lectores est facilisis est seacula 88 non. Gothica feugiat placerat aliquip autem imperdiet. 89 </p> 90 91 <form action="<?php echo($self); ?>" method="POST" class="examples"> 92 <p> 93 <input type="submit" name="submit" value="Go To Page 1"> 94 <input type="submit" name="submit" value="Go To Page 2"> 95 </p> 96 </form> 97 98 <?php 99 break; 100 } 101 ?> 102 103 103 </body> 103 </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'])); $submit = isset($_POST['submit']) ? $_POST['submit'] : 'Go To Page 1'; ?> <!doctype html> <html lang="en-us"> <head> <meta charset="utf-8"> <title>tedd's Examples</title> </head> <body> <?php switch($submit) { case 'Go To Page 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="submit" name="submit" value="Go To Page 2"> <input type="submit" name="submit" value="Go To Page 3"> </p> </form> <?php break; case 'Go To Page 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="submit" name="submit" value="Go To Page 3"> <input type="submit" name="submit" value="Go To Page 1"> </p> </form> <?php break; case 'Go To Page 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="<?php echo($self); ?>" method="POST" class="examples"> <p> <input type="submit" name="submit" value="Go To Page 1"> <input type="submit" name="submit" value="Go To Page 2"> </p> </form> <?php break; } ?> </body> </html>