Last active
October 6, 2019 19:47
-
-
Save krez69/a926868d74cd567e4c5d8dcb42a53cb4 to your computer and use it in GitHub Desktop.
formulaire avec redirection après validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "Merci à bientot"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$Firstname = $Lastname = $email = $comment = $number = ""; | |
$FirstnameErr = $LastnameErr = $emailErr = $numberErr = ""; | |
$err = 0; | |
if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_POST)) { | |
if (empty($_POST["Firstname"])) { | |
$FirstnameErr = "Firstname is required"; | |
$err++; | |
} else { | |
$Firstname = test_input($_POST["Firstname"]); | |
if (!preg_match("/^[a-zA-Z ]*$/", $Firstname)) { | |
$FirstnameErr = "Only letters and white space allowed"; | |
$err++; | |
} | |
} | |
if (empty($_POST["Lastname"])) { | |
$LastnameErr = "Lastname is required"; | |
$err++; | |
} else { | |
$Lastname = test_input($_POST["Lastname"]); | |
if (!preg_match("/^[a-zA-Z ]*$/", $LastnameErr)) { | |
$LastnameErr = "Only letters and white space allowed"; | |
$err++; | |
} | |
} | |
if (empty($_POST["email"])) { | |
$emailErr = "Email is required"; | |
$err++; | |
} else { | |
$email = test_input($_POST["email"]); | |
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
$emailErr = "Invalid email format"; | |
$err++; | |
} | |
} | |
if (empty($_POST["Number"])) { | |
$numberErr = "Number is required"; | |
$err++; | |
} else { | |
$number = test_input($_POST["Number"]); | |
if (!filter_var($number, FILTER_VALIDATE_REGEXP, array("options" => ['regexp' => '/[0-9]{10}/']))) { | |
$numberErr = "Invalid format"; | |
$err++; | |
} | |
} | |
if (empty($_POST["comment"])) { | |
$comment = ""; | |
} else { | |
$comment = test_input($_POST["comment"]); | |
} | |
if ($err == 0) { | |
header('Location: congratulation.php'); | |
} | |
} | |
function test_input($data) | |
{ | |
$data = trim($data); | |
$data = stripslashes($data); | |
$data = htmlspecialchars($data); | |
return $data; | |
} | |
?> | |
<form novalidate action="" method="post" class="sponsorship"> | |
<div class="sponsorship_div"> | |
<label for="Firstname" class="parrainage">Firstname</label> | |
<input id="Firstname" required type="text" name="Firstname" class="mb-4 form-control"> | |
<span class="error"><?php echo $FirstnameErr; ?></span> | |
</div> | |
<div> | |
<label for="Lastname" class="parrainage">Lastname</label> | |
<input id="Lastname" required type="text" name="Lastname" class="mb-4 form-control"> | |
<span class="error"><?php echo $LastnameErr; ?></span> | |
</div> | |
<div> | |
<label for="Number" class="parrainage">Number</label> | |
<input id="Number" required type="tel" name="Number" pattern="[0-9]{10}" class="mb-4 form-control"> | |
<span class="error"><?php echo $numberErr; ?></span> | |
</div> | |
<div> | |
<label for="email" class="parrainage">Write down your friend mail !</label> | |
<input id="email" required type="email" name="email" placeholder="[email protected]" class="mb-4 form-control"> | |
<span class="error"><?php echo $emailErr; ?></span> | |
</div> | |
<div> | |
<label for="select-option">Subject :</label> | |
<select name="pickle" id="select-option" class="mb-4 form-control"> | |
<option value="">--Please choose an option--</option> | |
<option value="A">A</option> | |
<option value="B">B</option> | |
<option value="C">C</option> | |
</select> | |
</div> | |
<label class="parrainage">Send a funny note with your sponsorship link :-)</label> | |
<div> | |
<textarea name="comment" placeholder="Hey john ! This may interest you :D" class="mb-4 form-control"></textarea> | |
</div> | |
<div class="sponsorship_div"> | |
<div class="g-recaptcha" data-sitekey="6LfFCrkUAAAAAA2Fc-mvzCL5wiZKoRXcfLMKwYzc"></div> | |
<br/> | |
<input type="submit" value="Submit" class="w-50 btn btn-success"> | |
</div> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment