Advertisement
Guest User

Untitled

a guest
May 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. <?php
  2. $first_name = '';
  3. $last_name = '';
  4. $city = '';
  5. $error = false;
  6. if(isset($_POST['first_name'])) {
  7. $first_name = $_POST['first_name'];
  8. }
  9. if(isset($_POST['last_name'])) {
  10. $last_name = $_POST['last_name'];
  11. }
  12. if(isset($_POST['city'])) {
  13. $city = $_POST['city'];
  14. }
  15. ?>
  16. <style>
  17. h2 {
  18. font-size: 15px;
  19. color: green;
  20. }
  21. .error {
  22. background-color: red;
  23. padding: 10px;
  24. font-size: 20px;
  25. color: white;
  26. }
  27. .fields {
  28. padding: 10px;
  29. }
  30. .button{
  31. padding: 10px;
  32. margin: 10px;
  33. font-size: 20px;
  34. border-radius: 10px;
  35. }
  36. </style>
  37.  
  38. <h1>My Final Project</h1>
  39. <hr />
  40.  
  41. <form method="POST">
  42. <div class="fields">
  43. <label for="first_name">First Name *</label>
  44. <input type="text" value="<?php echo $first_name; ?>"
  45. name="first_name"
  46. required="required">
  47. <?php
  48. if(isset($_POST['first_name']) &&
  49. empty($_POST['first_name'])) {
  50. echo "<div class='error'>
  51. *You must fill in all fields*
  52. </div>";
  53. }?>
  54. </div>
  55. <div class="fields">
  56. <label for="last_name">Last Name *</label>
  57. <input type="text" value="<?php echo $last_name; ?>"
  58. name="last_name"
  59. required="required">
  60. <?php
  61. if(isset($_POST['last_name']) &&
  62. empty($_POST['last_name'])) {
  63. echo "<div class='error'>
  64. *You must fill in all fields*
  65. </div>";
  66. }
  67. ?>
  68. </div>
  69. <div class="fields">
  70. <label for="city">City *</label>
  71. <input type="text" value="<?php echo $city; ?>"
  72. name="city"
  73. required="required">
  74. <?php
  75. if(isset($_POST['city']) &&
  76. empty($_POST['city'])) {
  77. echo "<div class='error'>
  78. *You must fill in all fields*
  79. </div>";
  80. }
  81. ?>
  82. </div>
  83. <button class="button" type="submit">Submit</button>
  84. </form>
  85.  
  86.  
  87.  
  88. <?php
  89. if($error = true) {
  90.  
  91. } else {
  92. echo "<h2>Form Submitted Successfully</h2>";
  93. }
  94.  
  95. print_r($_POST);
  96.  
  97. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement