Advertisement
dbcalmada

PHP Form

Jun 25th, 2016
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <title>Welcome!</title>
  5.     <meta charset="utf-8">
  6. </head>
  7. <body>
  8.     <?php
  9.         if (isset($_POST['username']) and $_POST['username']) {
  10.             $title = null;
  11.             if (isset($_POST['gender']) and $_POST['gender']) {
  12.                 switch ($_POST['gender']) {
  13.                     case 'male':
  14.                         $title = 'Mr.';
  15.                         break;
  16.                     case 'female':
  17.                         $title = 'Ms.';
  18.                         break;
  19.                     default:
  20.                         $title = null;
  21.                         break;
  22.                 }
  23.             }
  24.             echo "<h1>Welcome, " . $title . " " . $_POST['username'] . "!</h1>";
  25.             if (isset($_POST['email']) and $_POST['email']) {
  26.                 echo "<h2>We may contact you via email address ";
  27.                 echo $_POST['email'] . "</h2>";
  28.             }
  29.             if (isset($_POST['color']) and $_POST['color']) {
  30.                 echo "<h2>We're glad to know that your favorite color is ";
  31.                 echo "<span style='color:" . $_POST['color'] . "'>"
  32.                       . strtoupper($_POST['color']) . "</span><h2>";
  33.             }
  34.             echo "<p><a href='form_hello.php'>Go back to form</a></p>";
  35.         } else {
  36.             echo "<h2>What's your name again?</h2>";
  37.             echo "<p><a href='form_hello.php'>Let us know.</a></p>";
  38.         }
  39.     ?>     
  40. </body>
  41. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement