Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="fr">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Form</title>
  6. <link rel="stylesheet" href="style.css">
  7. </head>
  8.  
  9. <body>
  10.  
  11. <?php
  12.  
  13. $nameErr = $emailErr = $phoneErr = $firstnameErr = $selectErr = $msgErr = "";
  14. $name = $email = $phone = $firstname = $select = $msg = "";
  15.  
  16. $errors = 0;
  17.  
  18. function test_input($data) {
  19. $data = trim($data);
  20. $data = stripslashes($data);
  21. $data = htmlspecialchars($data);
  22. return $data;
  23. }
  24.  
  25. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  26. $name = test_input($_POST["user_name"]);
  27. $firstname = test_input($_POST["user_firstname"]);
  28. $email = test_input($_POST["user_mail"]);
  29. $phone = test_input($_POST["user_phone"]);
  30. $select = test_input($_POST["issue"]);
  31. $msg = test_input($_POST["user_message"]);
  32. }
  33.  
  34. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  35. if (empty($_POST["user_name"])) {
  36. $nameErr = "Nom obligatoire";
  37. $errors += 1;
  38. } else {
  39. $name = test_input($_POST["user_name"]);
  40. if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
  41. $nameErr = "Seulement lettres sans accents et espaces";
  42. $errors += 1;
  43. }
  44. }
  45.  
  46. if (empty($_POST["user_firstname"])) {
  47. $firstnameErr = "Prénom obligatoire";
  48. $errors += 1;
  49. } else {
  50. $firstname = test_input($_POST["user_firstname"]);
  51. if (!preg_match("/^[a-zA-Z ]*$/",$firstname)) {
  52. $firstnameErr = "Seulement lettres sans accents et espaces";
  53. $errors += 1;
  54. }
  55. }
  56.  
  57. if (empty($_POST["user_mail"])) {
  58. $emailErr = "Email obligatoire";
  59. $errors += 1;
  60. } else {
  61. $email = test_input($_POST["user_mail"]);
  62. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  63. $emailErr = "adresse email valide";
  64. $errors += 1;
  65. }
  66. }
  67.  
  68. if (empty($_POST["user_phone"])) {
  69. $phoneErr = "Numéro de téléphone obligatoire";
  70. $errors += 1;
  71. } else {
  72. $phone = test_input($_POST["user_phone"]);
  73. if (!preg_match("/[0-9]{10}/", $phone)) {
  74. $phoneErr = "10 numbers";
  75. $errors += 1;
  76. }
  77. }
  78.  
  79. if (empty($_POST["issue"])) {
  80. $selectErr = "Sélectionnez un sujet";
  81. $errors += 1;
  82. } else {
  83. $select = test_input($_POST["issue"]);
  84. }
  85.  
  86. if (empty($_POST["user_message"])) {
  87. $msgErr = "Indiquez votre message";
  88. $errors += 1;
  89. } else {
  90. $msg = test_input($_POST["user_message"]);
  91. }
  92.  
  93. if ($errors === 0){
  94. header("Location: success.php");
  95. exit();
  96. }
  97. }
  98.  
  99.  
  100.  
  101. ?>
  102.  
  103. <form action="form.php" method="post">
  104. <div>
  105. <label for="name">Nom :</label>
  106. <input type="text" id="name" name="user_name" required>
  107. <span class="error">* <?php echo $nameErr;?></span>
  108. </div>
  109. <div>
  110. <label for="firstname">Prénom :</label>
  111. <input type="text" id="firstname" name="user_firstname" required>
  112. <span class="error">* <?php echo $firstnameErr;?></span>
  113. </div>
  114. <div>
  115. <label for="mail">e-mail :</label>
  116. <input type="email" id="mail" name="user_mail" required>
  117. <span class="error">* <?php echo $emailErr;?></span>
  118. </div>
  119. <div>
  120. <label for="phone">Téléphone :</label>
  121. <input type="text" id="phone" name="user_phone" required>
  122. <span class="error">* <?php echo $phoneErr;?></span>
  123. </div>
  124. <div>
  125. <label for="issue-select">Sujet :</label>
  126. <select id="issue-select" name = "issue" required>
  127. <option value ="">--Choisissez une option--</option>
  128. <option value ="registration">Problème d'inscription</option>
  129. <option value ="connection">Problème de connexion</option>
  130. </select>
  131. <span class="error">* <?php echo $selectErr;?></span>
  132. </div>
  133. <div>
  134. <label for="msg">Message :</label>
  135. <textarea id="msg" name="user_message" ></textarea>
  136. <span class="error">* <?php echo $msgErr;?></span>
  137. </div>
  138. <div class="button">
  139. <button type="submit">Envoyer le message</button>
  140. </div>
  141. </form>
  142.  
  143. </body>
  144.  
  145. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement