reverting back

This commit is contained in:
Gary 2025-06-17 11:55:05 +01:00
parent 8f0dab9da5
commit 93224850f8

View File

@ -10,36 +10,33 @@ include_once $URlcorrection . "includes/header.php";
include_once $URlcorrection . "includes/banner.php"; include_once $URlcorrection . "includes/banner.php";
include_once $URlcorrection . "includes/nav.php"; include_once $URlcorrection . "includes/nav.php";
// Generate CAPTCHA numbers // Generate a new CAPTCHA question if not set
$num1 = rand(1, 10); if (!isset($_SESSION['captcha'])) {
$num2 = rand(1, 10); $_SESSION['captcha'] = [
$captchaAnswer = $num1 + $num2; 'num1' => rand(1, 10),
'num2' => rand(1, 10),
'answer' => $_SESSION['captcha']['num1'] + $_SESSION['captcha']['num2']
];
}
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['submit'])) { if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST['name']); $name = trim($_POST['name']);
$email = trim($_POST['email']); $email = trim($_POST['email']);
$phone = trim($_POST['phone']); $phone = trim($_POST['phone']);
$subject = trim($_POST['subject']); $subject = trim($_POST['subject']);
$message = trim($_POST['message']); $message = trim($_POST['message']);
$captcha_input = isset($_POST['captcha']) ? (int)$_POST['captcha'] : 0; $captcha_input = isset($_POST['captcha']) ? (int)$_POST['captcha'] : 0;
$submittedAnswer = isset($_POST['captcha_answer']) ? (int)$_POST['captcha_answer'] : null;
if ($captcha_input !== $submittedAnswer) { if ($captcha_input !== $_SESSION['captcha']['answer']) {
$errorMessage = "Incorrect CAPTCHA answer. Please try again."; echo "<div class='alert alert-danger text-center'>Incorrect CAPTCHA answer. Please try again.</div>";
// Store form data for re-population
$storedName = $name;
$storedEmail = $email;
$storedPhone = $phone;
$storedSubject = $subject;
$storedMessage = $message;
} else { } else {
$to = " enquiries@warmseal-roofing.co.uk"; $to = "enquiries@warmseal-roofing.co.uk";
$website_name = "Warmseal contact"; $website_name = "Warmseal Roofing contact";
$from_email = "noreply@" . $_SERVER['HTTP_HOST']; $from_email = "noreply@" . $_SERVER['HTTP_HOST'];
$headers = "From: " . $website_name . " <" . $from_email . ">" . "\r\n" . $headers = "From: " . $website_name . " <" . $from_email . ">" . "\r\n" .
"Reply-To: " . $name . " <" . $email . ">" . "\r\n" . "Reply-To: " . $name . " <" . $email . ">" . "\r\n" .
"X-Mailer: PHP/" . phpversion(); "X-Mailer: PHP/" . phpversion();
$body = "You have received a new message from Bedford Wealth Contact form:\n\n" . $body = "You have received a new message from Warmseal Roofing Contact form:\n\n" .
"Name: " . $name . "\n" . "Name: " . $name . "\n" .
"Email: " . $email . "\n"; "Email: " . $email . "\n";
if (!empty($phone)) { if (!empty($phone)) {
@ -49,28 +46,19 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['submit'])) {
"Message:\n" . $message; "Message:\n" . $message;
if (mail($to, 'New Message from ' . $website_name, $body, $headers)) { if (mail($to, 'New Message from ' . $website_name, $body, $headers)) {
header("Location: submission"); echo "<div class='alert alert-success text-center'>Thank you for contacting us. We will get back to you shortly.</div>";
exit();
} else { } else {
$errorMessage = "There was an error sending your message. Please try again."; echo "<div class='alert alert-danger text-center'>There was an error sending your message. Please try again.</div>";
// Store form data for re-population
$storedName = $name;
$storedEmail = $email;
$storedPhone = $phone;
$storedSubject = $subject;
$storedMessage = $message;
} }
} }
} else {
// Initialize stored data as empty on initial load
$storedName = '';
$storedEmail = '';
$storedPhone = '';
$storedSubject = '';
$storedMessage = '';
$errorMessage = null;
}
// Generate a new CAPTCHA for the next submission AFTER processing the form
$_SESSION['captcha'] = [
'num1' => rand(1, 10),
'num2' => rand(1, 10),
'answer' => $_SESSION['captcha']['num1'] + $_SESSION['captcha']['num2']
];
}
?> ?>