From bf53da13bec814b7fc83b88458043a43618d9a4d Mon Sep 17 00:00:00 2001
From: greggy
Date: Thu, 14 May 2026 22:38:27 +0000
Subject: [PATCH] Fix: Scroll to form result after submission (PRG pattern with
anchor)
---
index.php | 35 ++++++++++++++++++++++++++++-------
1 file changed, 28 insertions(+), 7 deletions(-)
diff --git a/index.php b/index.php
index 7f8e8e9..7c2b817 100644
--- a/index.php
+++ b/index.php
@@ -22,7 +22,20 @@ function containsHeaderInjection(string $value): bool
// --- Form processing ---
$formErrors = [];
$formSuccess = false;
-$formData = ['fname' => '', 'lname' => '', 'email' => '', 'phone' => '', 'interest' => 'Besichtigung anfragen', 'message' => ''];
+if (!empty($_SESSION['form_success'])) {
+ $formSuccess = true;
+ unset($_SESSION['form_success']);
+}
+if (!empty($_SESSION['form_errors'])) {
+ $formErrors = $_SESSION['form_errors'];
+ unset($_SESSION['form_errors']);
+}
+if (!empty($_SESSION['form_data'])) {
+ $formData = $_SESSION['form_data'];
+ unset($_SESSION['form_data']);
+} else {
+ $formData = ['fname' => '', 'lname' => '', 'email' => '', 'phone' => '', 'interest' => 'Besichtigung anfragen', 'message' => ''];
+}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Collect and normalize input
@@ -37,8 +50,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$honeypot = normalizeContactValue((string) ($_POST['website'] ?? ''));
if ($honeypot !== '') {
// Bot detected – pretend success
- $formSuccess = true;
- $formData = ['fname' => '', 'lname' => '', 'email' => '', 'phone' => '', 'interest' => 'Besichtigung anfragen', 'message' => ''];
+ header('Location: ' . $_SERVER['REQUEST_URI'] . '#form-result');
+ $_SESSION['form_success'] = true;
+ exit;
} else {
// Server-side validation
if ($formData['fname'] === '') {
@@ -91,14 +105,21 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$mailSent = mail($to, $subject, $body, $headers);
if ($mailSent) {
- $formSuccess = true;
$_SESSION['last_contact_submit'] = time();
- $formData = ['fname' => '', 'lname' => '', 'email' => '', 'phone' => '', 'interest' => 'Besichtigung anfragen', 'message' => ''];
+ header('Location: ' . $_SERVER['REQUEST_URI'] . '#form-result');
+ $_SESSION['form_success'] = true;
+ exit;
} else {
$formErrors[] = 'Leider konnte die E-Mail nicht gesendet werden. Bitte versuchen Sie es später erneut oder schreiben Sie uns direkt an mki@kies-media.de.';
}
}
}
+ if (!empty($formErrors)) {
+ header('Location: ' . $_SERVER['REQUEST_URI'] . '#form-result');
+ $_SESSION['form_errors'] = $formErrors;
+ $_SESSION['form_data'] = $formData;
+ exit;
+ }
}
?>
@@ -635,14 +656,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {