Fix: Scroll to form result after submission (PRG pattern with anchor)
All checks were successful
Deploy Feature Branch to Test / deploy (push) Successful in 23s

This commit is contained in:
2026-05-14 22:38:27 +00:00
parent 2307c379dc
commit bf53da13be

View File

@@ -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;
}
}
?>
<!doctype html>
@@ -635,14 +656,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
</p>
<div class="contact-form">
<?php if ($formSuccess): ?>
<div class="form-success" style="display: block">
<div id="form-result" class="form-success" style="display: block">
<p>Vielen Dank für Ihre Anfrage!</p>
<br />
<small>Wir haben Ihre Nachricht erhalten und melden uns innerhalb von 24 Stunden bei Ihnen.</small>
</div>
<?php else: ?>
<?php if (!empty($formErrors)): ?>
<div class="form-errors">
<div id="form-result" class="form-errors">
<ul>
<?php foreach ($formErrors as $error): ?>
<li><?= escapeContactValue($error) ?></li>