tdphp/td4/exo4.php
2023-03-22 00:13:04 -07:00

94 lines
No EOL
4.1 KiB
PHP

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
</head>
<body>
<div class="container p-5">
<h1> Formulaire </h1>
<form class="pt-3" method="POST" action="#">
<div class="mb-3">
<label for="nom" class="form-label">Nom :</label>
<input type="text" class="form-control" id="nom" name="nom">
</div>
<div class="mb-3">
<label for="email" class="form-label">Email :</label>
<input type="email" class="form-control" id="email" name="email">
</div>
<div class="mb-3">
<label for="url" class="form-label">URL :</label>
<input type="text" class="form-control" id="url" name="url">
</div>
<div class="mb-3">
<label for="message" class="form-label">Message :</label>
<textarea class="form-control" id="message" name="message"></textarea>
</div>
<div class="mb-3">
<label class="form-label">Choix unique :</label><br>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" id="choix1" name="choix" value="choix1">
<label class="form-check-label" for="choix1">Choix 1</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" id="choix2" name="choix" value="choix2">
<label class="form-check-label" for="choix2">Choix 2</label>
</div>
</div>
<div class="mb-3">
<label class="form-label">Choix multiples :</label><br>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="option1" name="options[]" value="option1">
<label class="form-check-label" for="option1">Option 1</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="option2" name="options[]" value="option2">
<label class="form-check-label" for="option2">Option 2</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="option3" name="options[]" value="option3">
<label class="form-check-label" for="option3">Option 3</label>
</div>
</div>
<input name="userIP" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" type="hidden">
<input name="userDATE" value="<?php echo date("Y-m-d H:i:s"); ?>" type="hidden">
<button type="submit" class="btn btn-primary">Envoyer</button>
</form>
<?php
if (isset($_POST['nom'])) {
echo "<h1> Réponse </h1>";
$mail = filter_var($_POST['email'], FILTER_SANITIZE_SPECIAL_CHARS);
$nom = filter_var($_POST['nom'], FILTER_SANITIZE_SPECIAL_CHARS);
$url = filter_var($_POST['url'], FILTER_SANITIZE_SPECIAL_CHARS);
echo "<p><strong>Nom : $nom</strong></p>";
echo "<p><strong>Email : $mail est <b>" . (filter_var($address, FILTER_VALIDATE_EMAIL) ? 'OK' : 'NOK') . " valide</b></p>";
echo "<p><strong>URL : $url est <b>" . (filter_var($url, FILTER_VALIDATE_URL) ? 'OK' : 'NOK') . " valide</b></p>";
}
?>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>