diff --git a/contact.php b/contact.php
index e7a3ca4..d98bac7 100644
--- a/contact.php
+++ b/contact.php
@@ -15,24 +15,31 @@ $num1 = rand(1, 10);
$num2 = rand(1, 10);
$captchaAnswer = $num1 + $num2;
-if ($_SERVER["REQUEST_METHOD"] == "POST") {
+if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['submit'])) {
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
$captcha_input = isset($_POST['captcha']) ? (int)$_POST['captcha'] : 0;
+ $submittedAnswer = isset($_POST['captcha_answer']) ? (int)$_POST['captcha_answer'] : null;
- if ($captcha_input !== $_SESSION['captcha']['answer']) {
- echo "
Incorrect CAPTCHA answer. Please try again.
";
+ if ($captcha_input !== $submittedAnswer) {
+ $errorMessage = "Incorrect CAPTCHA answer. Please try again.";
+ // Store form data for re-population
+ $storedName = $name;
+ $storedEmail = $email;
+ $storedPhone = $phone;
+ $storedSubject = $subject;
+ $storedMessage = $message;
} else {
- $to = "enquiries@warmseal-roofing.co.uk";
- $website_name = "Warmseal Roofing contact";
+ $to = " enquiries@warmseal-roofing.co.uk";
+ $website_name = "Warmseal contact";
$from_email = "noreply@" . $_SERVER['HTTP_HOST'];
$headers = "From: " . $website_name . " <" . $from_email . ">" . "\r\n" .
"Reply-To: " . $name . " <" . $email . ">" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
- $body = "You have received a new message from Warmseal Roofing Contact form:\n\n" .
+ $body = "You have received a new message from Bedford Wealth Contact form:\n\n" .
"Name: " . $name . "\n" .
"Email: " . $email . "\n";
if (!empty($phone)) {
@@ -42,20 +49,29 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
"Message:\n" . $message;
if (mail($to, 'New Message from ' . $website_name, $body, $headers)) {
- echo "Thank you for contacting us. We will get back to you shortly.
";
+ header("Location: submission");
+ exit();
} else {
- echo "There was an error sending your message. Please try again.
";
+ $errorMessage = "There was an error sending your message. Please try again.";
+ // Store form data for re-population
+ $storedName = $name;
+ $storedEmail = $email;
+ $storedPhone = $phone;
+ $storedSubject = $subject;
+ $storedMessage = $message;
}
}
-
- // 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']
- ];
+} else {
+ // Initialize stored data as empty on initial load
+ $storedName = '';
+ $storedEmail = '';
+ $storedPhone = '';
+ $storedSubject = '';
+ $storedMessage = '';
+ $errorMessage = null;
}
+
?>