Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $errors =[];
- // Debut Validation
- if ($_POST) {
- if (empty($_POST['lastname'])) {
- $errors['lastname'] = '* Nom invalide';
- }
- if (empty($_POST['firstname'])) {
- $errors['firstname'] = '* Prénom invalide';
- }
- if (empty($_POST['email'])) {
- $errors['email'] = "* Email invalide";
- }elseif(!filter_var($_POST['email'])){
- $errors['email'] = "* Ceci n'est pas un email";
- }
- if (empty($_POST['phone'])) {
- $errors['phone'] = '* Telephone invalide';
- }
- if ($_POST['subject'] == 'Unchoosen'){
- $errors['subject'] = '* Selectionnez un champ';
- }
- if (empty($_POST['message'])) {
- $errors['message'] = '* Message invalide';
- }
- // Check errors
- if(count($errors) == 0) {
- //Redirection vers page success
- header("location: success.php");
- exit();
- }
- }
- function test_input($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- ?>
- <!DOCTYPE html>
- <html lang="fr">
- <head>
- <meta charset="UTF-8">
- <meta name="description" content="">
- <title>Formulaire</title>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="">
- </head>
- <body>
- <h1>Formulaire</h1>
- <form method="POST" enctype="multipart/form-data" action="">
- <p>
- <label for="lastname">Nom :</label>
- <input type="text" id="lastname" name="lastname" value="<?php if(isset($_POST['lastname'])) echo $_POST['lastname'];?>">
- </p>
- <p><?php if(isset($errors['lastname'])) echo $errors['lastname'];?></p>
- <p>
- <label for="firstname">Prénom :</label>
- <input type="text" id="firstname" name="firstname" value="<?php if(isset($_POST['firstname'])) echo $_POST['firstname'];?>">
- </p>
- <p><?php if(isset($errors['firstname'])) echo $errors['firstname'];?></p>
- <p>
- <label for="email">e-mail :</label>
- <input type="email" id="email" name="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>">
- </p>
- <p><?php if(isset($errors['email'])) echo $errors['email'];?></p>
- <p>
- <label for="phone">Télephone :</label>
- <input type="text" id="phone" name="phone" value="<?php if(isset($_POST['phone'])) echo $_POST['phone'];?>">
- </p>
- <p><?php if(isset($errors['phone'])) echo $errors['phone'];?></p>
- <p>
- <label for="subject">Sujet traité :</label>
- <select id="subject" name="subject" required>
- <option value = "Unchoosen">--Faire un choix--</option>
- <option value = "Sujet 1">Sujet 1</option>
- <option value = "Sujet 2">Sujet 2</option>
- <option value = "Sujet 3">Sujet 3</option>
- </select>
- </p>
- <p><?php if(isset($errors['subject'])) echo $errors['subject'];?></p>
- <p>
- <label for="msg">Message :</label>
- <textarea id="msg" name="message" rows="10" cols="30" required></textarea>
- </p>
- <p><?php if(isset($errors['message'])) echo $errors['message'];?></p>
- <div class="button">
- <button type="submit">Envoyer le message</button>
- </div>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement