Skip to content

Instantly share code, notes, and snippets.

@MkLHX
Last active November 6, 2018 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MkLHX/657b0a974bf2e6d429e26efd62334c98 to your computer and use it in GitHub Desktop.
Save MkLHX/657b0a974bf2e6d429e26efd62334c98 to your computer and use it in GitHub Desktop.
<?php
if (isset($_POST['submit'])) {
$posts = [];
foreach ($_POST as $key => $post) {
$posts[] = htmlspecialchars(stripslashes(trim($post)));
}
$nom = $posts['nom'];
$prenom = $posts['prenom'];
$email = $posts['email'];
$telephone = $posts['telephone'];
$sujet = $posts['sujet'];
$message = $posts['message'];
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Formulaire de Contact</title>
</head>
<body>
<main>
<?php
if (count($posts) >= 6) {
echo "<strong style='color:cornflowerblue;'>Féliciations!!! vous avez tout bien remplis le formulaire!</strong>";
}
?>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div>
<label for="nom">Nom :</label>
<input type="text" id="nom" name="nom" required minlength="1"
value="<?php echo $_POST['nom']; ?>">
<?php (empty($_POST['nom'])) ? '<p style="color:red;">* le champ nom est requis</p>' : ''; ?>
</div>
<div>
<label for="prenom">Prénom :</label>
<input type="text" id="prenom" name="prenom" required minlength="1"
value="<?php echo $_POST['prenom']; ?>">
<?php (empty($_POST['prenom'])) ? '<p style="color:red;">* le champ prenom est requis</p>' : ''; ?>
</div>
<div>
<label for="telephone">Téléphone :</label>
<input type="tel" id="telephone" name="telephone" required minlength="10" maxlength="10"
pattern="^(?=.*[1-9]).*$"
value="<?php echo $_POST['telephone']; ?>">
<?php (empty($_POST['telephone'])) ? '<p style="color:red;">* le champ téléphone est requis</p>' : ''; ?>
</div>
<div>
<label for="email">Email :</label>
<input type="email" id="email" name="email" required
pattern="^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*(\.\w{2,})+$"
value="<?php echo $_POST['email']; ?>">
<?php (empty($_POST['email'])) ? '<p style="color:red;">* le champ email est requis</p>' : ''; ?>
</div>
<div>
<label for="sujet">Sujet :</label>
<select name="sujet" id="sujet" required>
<?php
$selected = ['star_wars' => 'selected', 'back_to_the_future' => 'selected', 'Lord_of_the_rings' => 'selected'];
echo "<option value=''>Choisir le sujet de l'email</option>";
echo "<option value='star_wars'" . $selected[$_POST['sujet']] . ">Star Wars</option>";
echo "<option value='back_to_the_future'" . $selected[$_POST['sujet']] . ">Retour vers le futur</option>";
echo "<option value='Lord_of_the_rings'" . $selected[$_POST['sujet']] . ">Le seigneur des anneaux</option>";
?>
</select>
<?php (empty($_POST['sujet'])) ? '<p style="color:red;">* le champ sujet est requis</p>' : ''; ?>
</div>
<div>
<label for="message">Message :</label>
<textarea id="message" name="message" required minlength="80">
<?php echo $_POST['message']; ?>
</textarea>
<?php (empty($_POST['message'])) ? '<p style="color:red;">* le champ message est requis</p>' : ''; ?>
</div>
<div class="button">
<button type="submit" name="submit">Envoyer votre message</button>
</div>
</form>
</main>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment