Advertisement
dimipan80

Form Data

Dec 2nd, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. <!--Write a PHP script GetFormData.php which retrieves the input data from an HTML form, and displays it as string.
  2. The input fields should hold name, age and gender (radio buttons). The returned string should be a message
  3. containing the information submitted by the form. 100% accuracy is NOT required. Semantic HTML is required.-->
  4.  
  5. <!DOCTYPE html>
  6. <html>
  7. <head lang="en">
  8.     <meta content="text/html" charset="UTF-8">
  9.     <title>Form Data</title>
  10.     <style type="text/css">
  11.         form {
  12.             margin-bottom: 15px;
  13.         }
  14.  
  15.         p {
  16.             padding: 2px;
  17.             margin: 0;
  18.         }
  19.     </style>
  20. </head>
  21. <body>
  22. <form action="#" method="post">
  23.     <p><input type="text" name="username" maxlength="25" placeholder="Name..." required/></p>
  24.  
  25.     <p><input type="number" name="age" min="1" max="100" placeholder="Age..." required/></p>
  26.  
  27.     <p><input type="radio" name="gender" value="male" id="gender-male" checked="checked"/><label
  28.             for="gender-male">Male</label></p>
  29.  
  30.     <p><input type="radio" name="gender" value="female" id="gender-female"/><label
  31.             for="gender-female">Female</label></p>
  32.     <input type="submit" value="Submit"/>
  33. </form>
  34. <?php
  35. mb_internal_encoding("UTF-8");
  36. if (count($_POST) == 3) {
  37.     $username = trim($_POST['username']);
  38.     $age = $_POST['age'];
  39.     $gender = $_POST['gender'];
  40.  
  41.     echo '<p>My name is ' . htmlspecialchars($username) . '. I am ' . htmlspecialchars($age) .
  42.         ' years old. I am ' . htmlspecialchars($gender) . ".</p>\n";
  43. }
  44. ?>
  45. </body>
  46. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement