Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. <?php
  2.  
  3. $errors =[];
  4.  
  5. // Debut Validation
  6.  
  7. if ($_POST) {
  8. if (empty($_POST['lastname'])) {
  9. $errors['lastname'] = '* Nom invalide';
  10. }
  11.  
  12. if (empty($_POST['firstname'])) {
  13. $errors['firstname'] = '* Prénom invalide';
  14. }
  15.  
  16. if (empty($_POST['email'])) {
  17. $errors['email'] = "* Email invalide";
  18. }elseif(!filter_var($_POST['email'])){
  19. $errors['email'] = "* Ceci n'est pas un email";
  20. }
  21. if (empty($_POST['phone'])) {
  22. $errors['phone'] = '* Telephone invalide';
  23. }
  24.  
  25. if ($_POST['subject'] == 'Unchoosen'){
  26. $errors['subject'] = '* Selectionnez un champ';
  27. }
  28. if (empty($_POST['message'])) {
  29. $errors['message'] = '* Message invalide';
  30. }
  31.  
  32. // Check errors
  33. if(count($errors) == 0) {
  34. //Redirection vers page success
  35. header("location: success.php");
  36. exit();
  37. }
  38. }
  39. function test_input($data) {
  40. $data = trim($data);
  41. $data = stripslashes($data);
  42. $data = htmlspecialchars($data);
  43. return $data;
  44. }
  45.  
  46. ?>
  47.  
  48. <!DOCTYPE html>
  49. <html lang="fr">
  50.  
  51. <head>
  52. <meta charset="UTF-8">
  53. <meta name="description" content="">
  54. <title>Formulaire</title>
  55. <meta name="viewport" content="width=device-width, initial-scale=1">
  56. <link rel="stylesheet" href="">
  57. </head>
  58.  
  59. <body>
  60. <h1>Formulaire</h1>
  61. <form method="POST" enctype="multipart/form-data" action="">
  62. <p>
  63. <label for="lastname">Nom :</label>
  64. <input type="text" id="lastname" name="lastname" value="<?php if(isset($_POST['lastname'])) echo $_POST['lastname'];?>">
  65. </p>
  66. <p><?php if(isset($errors['lastname'])) echo $errors['lastname'];?></p>
  67.  
  68. <p>
  69. <label for="firstname">Prénom :</label>
  70. <input type="text" id="firstname" name="firstname" value="<?php if(isset($_POST['firstname'])) echo $_POST['firstname'];?>">
  71. </p>
  72. <p><?php if(isset($errors['firstname'])) echo $errors['firstname'];?></p>
  73.  
  74. <p>
  75. <label for="email">e-mail :</label>
  76. <input type="email" id="email" name="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>">
  77. </p>
  78. <p><?php if(isset($errors['email'])) echo $errors['email'];?></p>
  79.  
  80. <p>
  81. <label for="phone">Télephone :</label>
  82. <input type="text" id="phone" name="phone" value="<?php if(isset($_POST['phone'])) echo $_POST['phone'];?>">
  83. </p>
  84. <p><?php if(isset($errors['phone'])) echo $errors['phone'];?></p>
  85.  
  86. <p>
  87. <label for="subject">Sujet traité :</label>
  88. <select id="subject" name="subject" required>
  89. <option value = "Unchoosen">--Faire un choix--</option>
  90. <option value = "Sujet 1">Sujet 1</option>
  91. <option value = "Sujet 2">Sujet 2</option>
  92. <option value = "Sujet 3">Sujet 3</option>
  93. </select>
  94. </p>
  95. <p><?php if(isset($errors['subject'])) echo $errors['subject'];?></p>
  96. <p>
  97. <label for="msg">Message :</label>
  98. <textarea id="msg" name="message" rows="10" cols="30" required></textarea>
  99. </p>
  100. <p><?php if(isset($errors['message'])) echo $errors['message'];?></p>
  101. <div class="button">
  102. <button type="submit">Envoyer le message</button>
  103. </div>
  104. </form>
  105.  
  106. </body>
  107. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement