Fix form
continuous-integration/drone/push Build is passing Details

master
cocaillot 7 months ago
parent 976c45d022
commit c85b6616c0

@ -9,32 +9,31 @@
<link type="text/css" rel="stylesheet" href="style.css">
<script src="effect.js" defer></script>
</head>
<body class="bg-gray-900 text-white">
<body class="bg-gray-50 text-gray-800">
<!-- Navigation (Optional) -->
<nav class="navbar bg-gray-800">
<ul class="navbar-list">
<li><a href="index.html">Accueil</a></li>
<li><a href="cursus.html">Cursus</a></li>
<li><a href="planning.html">Planning</a></li>
<li class="dropdown">
<a href="#">Gallerie</a>
<ul class="dropdown-content">
<li><a href="images.html">Images</a></li>
<li><a href="videos.html">Vidéos</a></li>
<!-- Navigation -->
<nav class="navbar bg-gray-200 shadow-lg">
<ul class="navbar-list flex justify-around items-center py-4">
<li><a href="index.html" class="text-gray-700 hover:text-blue-500">Accueil</a></li>
<li><a href="cursus.html" class="text-gray-700 hover:text-blue-500">Cursus</a></li>
<li><a href="planning.html" class="text-gray-700 hover:text-blue-500">Planning</a></li>
<li class="dropdown relative">
<a href="#" class="text-gray-700 hover:text-blue-500">Gallerie</a>
<ul class="dropdown-content absolute left-0 mt-2 bg-white shadow-lg p-4 hidden">
<li><a href="images.html" class="hover:text-blue-500">Images</a></li>
<li><a href="videos.html" class="hover:text-blue-500">Vidéos</a></li>
</ul>
</li>
<li><a href="form.html">Formulaire</a></li>
<li><a href="form.html" class="text-gray-700 hover:text-blue-500">Formulaire</a></li>
<label class="switch">
<input type="checkbox" id="theme-switch">
<span class="slider"></span>
</label>
</ul>
</nav>
<!-- Contact Form -->
<form action="process_form.php" method="POST" id="contact-form">
<div class="container px-4 mx-auto mt-10">
<div class="max-w-md mx-auto px-8 py-6 bg-gray-800 rounded-lg shadow-lg">
<h2 class="text-2xl font-semibold text-white mb-4">Contact Us</h2>
@ -79,6 +78,37 @@
</div>
</div>
<!-- JavaScript to Handle Form Submission -->
<script>
document.getElementById('contact-form').addEventListener('submit', function (e) {
e.preventDefault();
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const message = document.getElementById('message').value;
// Display confirmation message
const responseMessage = document.getElementById('form-response');
responseMessage.textContent = `Thank you, ${name}! Your message has been sent successfully.`;
responseMessage.classList.remove('hidden');
// Clear the form
e.target.reset();
// Example: Send data via fetch to a backend API (optional)
/*
fetch('your-backend-endpoint', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ name, email, message })
});
*/
});
</script>
</body>
</html>

@ -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.";
}
}
?>

@ -229,6 +229,7 @@ body.light-mode .right::before {
}
h1, h2:not(.exclude), h3:not(.exclude) {
color: #ffffff;
}

Loading…
Cancel
Save