Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. <?php
  2.  
  3. if($_POST)
  4. {
  5. $errors = array();
  6. //start validations
  7. if(empty($_POST['firstName']))
  8. {
  9. $errors['firstName1'] = "Your first name needs to be completed";
  10. }
  11. if(empty($_POST['lastName']))
  12. {
  13. $errors['lastName1'] = "Your last name needs to be completed";
  14. }
  15. if(empty($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
  16. {
  17. $emailErr = "Invalid email format";
  18. $errors['email1'] = "Invalid email format";
  19. }
  20. if(empty($_POST['phoneNumber']))
  21. {
  22. $errors['phoneNumber1'] = "Your phone number needs to be completed";
  23. }
  24. if(empty($_POST['choice']))
  25. {
  26. $errors['choice1'] = "You have to do a choice";
  27. }
  28. if(empty($_POST['msg']))
  29. {
  30. $errors['msg1'] = "Your message needs to be completed";
  31. }
  32.  
  33. //check errors
  34. if(count($errors) == 0)
  35. {
  36. //success page
  37. header("Location: success.php");
  38. exit();
  39. }
  40. }
  41.  
  42. ?>
  43.  
  44. <!DOCTYPE html>
  45. <html lang="en">
  46. <head>
  47. <meta charset="UTF-8">
  48. <title>Form !</title>
  49. </head>
  50. <body>
  51. <form action="form.php" method="post" target="">
  52. <h2 class="title">Contact us</h2>
  53. <div>
  54. <label for="firstName">First name </label>
  55. <input type="text" placeholder="Hugo" name="firstName" id="firstName" value="<?php if(isset($_POST['firstName'])) echo $_POST['firstName']; ?>" required/>
  56. </div>
  57. <p><?php if(isset($errors['firstName1'])) echo $errors['firstName1']; ?></p>
  58. <div>
  59. <label for="lastName">Last name </label>
  60. <input type="text" placeholder="Gehl" name="lastName" id="lastName" value="<?php if(isset($_POST['lastName'])) echo $_POST['lastName']; ?>" required/>
  61. </div>
  62. <p><?php if(isset($errors['lastName1'])) echo $errors['lastName1']; ?></p>
  63. <div>
  64. <label for="email">Email </label>
  65. <input type="email" placeholder="hugogehl@exemple.com" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" required/>
  66. </div>
  67. <p>
  68. <style>
  69. p {
  70. color: red;
  71. }
  72. </style>
  73. <?php if(isset($errors['email1'])) echo $errors['email1']; ?>
  74. </p>
  75. <div>
  76. <label for="phoneNumber">Phone number </label>
  77. <input type="tel" placeholder="0625234595" name="phoneNumber" id="phoneNumber" value="<?php if(isset($_POST['phoneNumber'])) echo $_POST['phoneNumber']; ?>" required pattern="^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$"/>
  78. </div>
  79. <p><?php if(isset($errors['phoneNumber1'])) echo $errors['phoneNumber1']; ?></p>
  80. <div>
  81. <label for="choice">Do your choice</label>
  82. <select id="choice" name="choice" required>
  83. <option value="">-- Do your choice --</option>
  84. <option value="Subject one">Subject one</option>
  85. <option value="Subject two">Subject two</option>
  86. <option value="Subject three">Subject three</option>
  87. </select>
  88. </div>
  89. <p><?php if(isset($errors['choice'])) echo $errors['choice1']; ?></p>
  90. <div>
  91. <label for="msg">Message </label>
  92. <textarea placeholder="Your message" id="msg" name="msg" required></textarea>
  93. </div>
  94. <p><?php if(isset($errors['msg1'])) echo $errors['msg1']; ?></p>
  95. <div class="button">
  96. <button type="submit" value="submit">Send !</button>
  97. </div>
  98. </form>
  99. </body>
  100. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement