generated from Templates_CodeFirst/templateHtmlCss
Fix form
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
976c45d022
commit
c85b6616c0
@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
// Initialisation des variables d'erreur
|
|
||||||
$errors = [];
|
|
||||||
$data = [];
|
|
||||||
|
|
||||||
// Vérification des champs obligatoires
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'GET' || $_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
||||||
$data['name'] = !empty($_REQUEST['name']) ? trim($_REQUEST['name']) : null;
|
|
||||||
$data['email'] = !empty($_REQUEST['email']) ? trim($_REQUEST['email']) : null;
|
|
||||||
$data['message'] = !empty($_REQUEST['message']) ? trim($_REQUEST['message']) : null;
|
|
||||||
$data['phone'] = isset($_REQUEST['phone']) ? trim($_REQUEST['phone']) : '';
|
|
||||||
$data['reason'] = isset($_REQUEST['reason']) ? $_REQUEST['reason'] : '';
|
|
||||||
$data['schedule'] = isset($_REQUEST['schedule']) ? $_REQUEST['schedule'] : '';
|
|
||||||
$data['first_request'] = isset($_REQUEST['first_request']) ? $_REQUEST['first_request'] : '';
|
|
||||||
|
|
||||||
// Vérifications des champs obligatoires
|
|
||||||
if (!$data['name']) $errors[] = "Le champ 'Nom' est obligatoire.";
|
|
||||||
if (!$data['email']) $errors[] = "Le champ 'Adresse de courriel' est obligatoire.";
|
|
||||||
if (!$data['message']) $errors[] = "Le champ 'Message' est obligatoire.";
|
|
||||||
|
|
||||||
// Validation de l'adresse email
|
|
||||||
if ($data['email'] && !filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
|
|
||||||
$errors[] = "Le format de l'adresse de courriel est invalide.";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Affichage des erreurs ou récapitulatif
|
|
||||||
if ($errors) {
|
|
||||||
echo "<h2>Erreurs dans le formulaire :</h2><ul>";
|
|
||||||
foreach ($errors as $error) {
|
|
||||||
echo "<li>" . htmlspecialchars($error) . "</li>";
|
|
||||||
}
|
|
||||||
echo "</ul>";
|
|
||||||
echo "<a href='index.html'>Retour au formulaire</a>";
|
|
||||||
} else {
|
|
||||||
echo "<h2>Récapitulatif de votre demande</h2>";
|
|
||||||
echo "<p><strong>Nom :</strong> " . htmlspecialchars($data['name']) . "</p>";
|
|
||||||
echo "<p><strong>Adresse de courriel :</strong> " . htmlspecialchars($data['email']) . "</p>";
|
|
||||||
echo "<p><strong>Numéro de téléphone :</strong> " . htmlspecialchars($data['phone']) . "</p>";
|
|
||||||
echo "<p><strong>Motif de contact :</strong> " . htmlspecialchars($data['reason']) . "</p>";
|
|
||||||
echo "<p><strong>Créneau horaire :</strong> " . htmlspecialchars($data['schedule']) . "</p>";
|
|
||||||
echo "<p><strong>Première demande :</strong> " . ($data['first_request'] === 'yes' ? 'Oui' : 'Non') . "</p>";
|
|
||||||
echo "<p><strong>Message :</strong> " . nl2br(htmlspecialchars($data['message'])) . "</p>";
|
|
||||||
echo "<p>Votre demande a été prise en compte et sera étudiée.</p>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$name = htmlspecialchars($_POST['name']);
|
||||||
|
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
|
||||||
|
$message = htmlspecialchars($_POST['message']);
|
||||||
|
|
||||||
|
if ($name && $email && $message) {
|
||||||
|
// Recipient email
|
||||||
|
$to = "corentin.caillot03@gmail.com";
|
||||||
|
|
||||||
|
// Email subject
|
||||||
|
$subject = "New Contact Form Submission";
|
||||||
|
|
||||||
|
// Email content
|
||||||
|
$body = "You have received a new message from your website's contact form:\n\n";
|
||||||
|
$body .= "Name: $name\n";
|
||||||
|
$body .= "Email: $email\n";
|
||||||
|
$body .= "Message:\n$message\n";
|
||||||
|
|
||||||
|
// Email headers
|
||||||
|
$headers = "From: $email";
|
||||||
|
|
||||||
|
// Send the email
|
||||||
|
if (mail($to, $subject, $body, $headers)) {
|
||||||
|
echo "Your message has been sent successfully!";
|
||||||
|
} else {
|
||||||
|
echo "There was an issue sending your message. Please try again later.";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "Invalid input. Please make sure all fields are filled out correctly.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
Loading…
Reference in new issue