Skip to content

Instantly share code, notes, and snippets.

@Jules59
Last active March 12, 2018 15:59
Show Gist options
  • Save Jules59/a5c20c7930438f5a3e9f95f038e043c7 to your computer and use it in GitHub Desktop.
Save Jules59/a5c20c7930438f5a3e9f95f038e043c7 to your computer and use it in GitHub Desktop.
Les formulaires
<?php
if ($_POST)
{
$errors = array();
//Part Lastname
if(empty($_POST["lastname"])) {
$errors['lastname'] = "lastname is required";
}
if(strlen($_POST["lastname"]) < 2 || strlen($_POST["lastname"]) > 30) {
$errors['lastname2'] = "Lastname must be atleast between 3 and 30 characters long";
}
//Part Firstname
if(empty($_POST["firstname"])) {
$errors['firstname'] = "<p>firstname is required<p>";
}
if(strlen($_POST["firstname"]) < 2 || (strlen($_POST["firstname"])) > 30) {
$errors['firsystname2'] = "<p>firstname must be atleast 3 characters long<p>";
}
//Part email
if(!preg_match('#^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#',$_POST['email'])) {
$errors['email'] = "<p>email is not valid</p>";
}
if(strlen($_POST["email"]) < 6) {
$errors['email2'] = "<p>email must have atleast 6 characters long</p>";
}
//Part number
if(!preg_match('#^0[1-9]([-. ]?\d{2}){4}$#',$_POST['tel'])) {
$errors['tel'] = "<p>phone is required</p>";
}
//Part text
if(empty($_POST["text"])) {
$errors['text'] = "text is required";
}
if(strlen($_POST["text"]) > 100) {
$errors['text2'] = "<p>Your comment must have less 100 characters</p>";
}
//Part Succes
if(count($errors) == 0){
echo "<center><h1>Successfull</h1></center>";
echo$_POST["lastname"] = " ";
echo$_POST["firstname"] = " ";
echo$_POST["email"] = empty($_POST["email"]);
echo$_POST["tel"] = " ";
echo$_POST["text"] = " ";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>FORMULAIRE</title>
</head>
<body>
<form method="post" action="">
<!--Part lastname-->
<label for="lastname">Votre nom</label>
<input type="text" name="lastname" id="name" maxlength="20"
placeholder="<?php if(isset($_POST['lastname'])) echo "ex: Bond"; ?>"
value="<?php if(isset($_POST['lastname'])) echo $_POST['lastname']; ?>">
<br>
<p><?php if(isset($errors['lastname'])) echo $errors['lastname']; ?></p>
<p><?php if(isset($errors['lastname2'])) echo $errors['lastname2']; ?></p>
<!--Part firstname-->
<label for="firstname">Votre prénom</label>
<input type="text" name="firstname" id="firstname" maxlength="20"
placeholder="<?php if(isset($_POST['firstname'])) echo "ex: James"; ?>"
value="<?php if(isset($_POST['firstname'])) echo $_POST['firstname']; ?>">
<br>
<p><?php if(isset($errors['firstname'])) echo $errors['firstname']; ?></p>
<p><?php if(isset($errors['firstname2'])) echo $errors['firstname2']; ?></p>
<!--Part email-->
<label for="email">Votre email</label>
<input type="email" name="email" id="email"
placeholder="<?php if(isset($_POST['email'])) echo "ex: [email protected]"; ?>"
value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>">
<br>
<p><?php if(isset($errors['email'])) echo $errors['email']; ?></p>
<p><?php if(isset($errors['email2'])) echo $errors['email2']; ?></p>
<!--Part phone-->
<label for="tel">Telephone</label>
<input type="tel" name="tel" id="tel"
placeholder="<?php if(isset($_POST['tel'])) echo "ex: 0612131415"; ?>"
value="<?php if(isset($_POST['tel'])) echo $_POST['tel']; ?>">
<br>
<p><?php if(isset($errors['tel'])) echo $errors['tel']; ?></p>
<!--Part question-->
<label for="question">Quel est votre objet ?</label>
<select name="question" id="question">
<option value="1">Integration à la Wild code School</option>
<option value="2">Autre</option>
</select>
<br>
<!--Part textarea-->
<textarea name="text" rows="5" cols="100"
placeholder="<?php if(isset($_POST['text'])) echo "Don't forget to put a message"; ?>"
><?php if(isset($_POST['text'])) echo $_POST['text']; ?></textarea>
<br>
<p><?php if(isset($errors['text'])) echo $errors['text']; ?></p>
<button type="submit">Envoyer</button>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment