Advertisement
StessieFlt

Untitled

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