Advertisement
StessieFlt

Untitled

Oct 3rd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. $nameError = '';
  5.  
  6. $firstNameError = '';
  7.  
  8. $emailError = '';
  9.  
  10. $phoneError = '';
  11.  
  12. $subjectError = '';
  13.  
  14. $messageError = '';
  15.  
  16.  
  17.  
  18. if (isset($_POST['isFormSubmitted']))
  19.  
  20. {
  21.  
  22. $name = $_POST['name'];
  23.  
  24. $firstName = $_POST['firstName'];
  25.  
  26. $email = $_POST['email'];
  27.  
  28. $phone = $_POST['phone'];
  29.  
  30. $subject = $_POST['subject'];
  31.  
  32. $message = $_POST['message'];
  33.  
  34.  
  35.  
  36. if (empty($name) === true)
  37.  
  38. {
  39.  
  40. $nameError = '<br> Erreur : champ invalide';
  41.  
  42. }
  43.  
  44.  
  45.  
  46. if (empty($fisrtName) === true)
  47.  
  48. {
  49.  
  50. $firstNameError = '<br> Erreur : champ invalide';
  51.  
  52. }
  53.  
  54.  
  55.  
  56. if (empty($email) === true)
  57.  
  58. {
  59.  
  60. $emailError = '<br> Erreur : champ invalide';
  61.  
  62. }
  63.  
  64.  
  65.  
  66. if (empty($phone) === true)
  67.  
  68. {
  69.  
  70. $phoneError = '<br> Erreur : champ invalide';
  71.  
  72. }
  73.  
  74.  
  75.  
  76. if (empty($subject) === true)
  77.  
  78. {
  79.  
  80. $subjectError = '<br> Erreur : champ invalide';
  81.  
  82. }
  83.  
  84.  
  85.  
  86. if (empty($message) === true)
  87.  
  88. {
  89.  
  90. $messageError = '<br> Erreur : champ invalide';
  91.  
  92. }
  93.  
  94.  
  95.  
  96. $variable = filter_var( $email,FILTER_VALIDATE_EMAIL);
  97.  
  98.  
  99.  
  100. if ($variable === false)
  101.  
  102. {
  103.  
  104. $emailError = 'Bad email';
  105.  
  106. }
  107.  
  108.  
  109.  
  110. if (
  111.  
  112. empty($nameError) && empty($firstNameError) && empty($emailError) &&
  113.  
  114. empty($subjectErrorError) && empty($messageErrorError) && empty($phoneErrorError)
  115.  
  116. )
  117.  
  118. {
  119.  
  120. header("Location: index.html");
  121.  
  122. }
  123.  
  124.  
  125.  
  126. }
  127.  
  128. ?>
  129.  
  130.  
  131.  
  132. <!DOCTYPE html>
  133.  
  134. <html lang="fr">
  135.  
  136. <head>
  137.  
  138. <meta charset="UTF-8">
  139.  
  140. <title>Formulaire PHP</title>
  141.  
  142. <meta name="">
  143.  
  144. </head>
  145.  
  146. <body>
  147.  
  148. <form action="form.php" method="post">
  149.  
  150. <p>
  151.  
  152. <label for="name">Nom :*</label>
  153.  
  154. <input type="text" id="name" name="name" required>
  155.  
  156. </p>
  157.  
  158. <?php echo $nameError ?>
  159.  
  160. <p>
  161.  
  162. <label for="firstName">FirstName :*</label>
  163.  
  164. <input type="text" id="firstName" name="firstName" required>
  165.  
  166. </p>
  167.  
  168. <?php echo $firstNameError ?>
  169.  
  170. <p>
  171.  
  172. <label for="email">E-mail :*</label>
  173.  
  174. <input type="text" id="email" name="email" required>
  175.  
  176. </p>
  177.  
  178. <?php echo $emailError ?>
  179.  
  180. <p>
  181.  
  182. <label for="phone">Enter your phone number:*</label>
  183.  
  184.  
  185.  
  186. <input type="tel" id="phone" name="phone" required
  187.  
  188. pattern="^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$">
  189.  
  190. </p>
  191.  
  192. <?php echo $phoneError ?>
  193.  
  194. <p>
  195.  
  196. <label for="subject">Choose an option:*</label>
  197.  
  198.  
  199.  
  200. <select id="subject" name="subject" required>
  201.  
  202. <option value=""> Please choose an option </option>
  203.  
  204. <option value="option1">Option 1</option>
  205.  
  206. <option value="option2">Option 2</option>
  207.  
  208. </select>
  209.  
  210. </p>
  211.  
  212. <?php echo $subjectError ?>
  213.  
  214. <p>
  215.  
  216. <label for="message">Message :*</label>
  217.  
  218. <textarea id="message" name="message" required></textarea>
  219.  
  220. </p>
  221.  
  222. <?php echo $messageError ?>
  223.  
  224. <div class="button">
  225.  
  226. <button type="submit" name="isFormSubmitted">Send your message :
  227.  
  228. </button>
  229.  
  230. </div>
  231.  
  232. </form>
  233.  
  234. </body>
  235.  
  236. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement