Add honeypot, spam protection to contact form

This commit is contained in:
2026-05-02 11:24:11 +12:00
parent cd8d581f7a
commit 3587ba7f26
25 changed files with 553 additions and 41 deletions
+32
View File
@@ -1,4 +1,5 @@
<script lang="ts">
import { onMount } from 'svelte';
import Icon from '$lib/components/Icon.svelte';
import SuccessModal from '$lib/components/SuccessModal.svelte';
import ErrorModal from '$lib/components/ErrorModal.svelte';
@@ -17,6 +18,8 @@
let location = '';
let message = '';
let selectedServices: string[] = [];
let website = '';
let formStartedAt = 0;
let fullNameInput: HTMLInputElement;
let emailInput: HTMLInputElement;
@@ -63,6 +66,10 @@
$: ownerStepLabel = booking.ownerStepLabel?.trim() || 'Owner Details';
$: dogStepLabel = booking.dogStepLabel?.trim() || 'Your dog';
onMount(() => {
formStartedAt = Date.now();
});
function splitBookingTitle(title: string) {
const trimmed = title.trim();
const lastSpace = trimmed.lastIndexOf(' ');
@@ -147,6 +154,8 @@
body: JSON.stringify({
fullName, email, phone, petName, location, message,
services: selectedServices,
website,
formStartedAt,
referrer: document.referrer,
page: window.location.href,
}),
@@ -224,6 +233,18 @@
novalidate
on:submit={handleSubmit}
>
<div class="booking-honeypot" aria-hidden="true">
<label for="website">Website</label>
<input
bind:value={website}
type="text"
id="website"
name="website"
tabindex="-1"
autocomplete="new-password"
/>
</div>
{#if step === 1}
<div class="booking-panel">
{#if hasBanner}
@@ -443,4 +464,15 @@
opacity: 1;
transform: translate3d(0, 0, 0);
}
.booking-honeypot {
position: absolute;
left: -10000px;
top: auto;
width: 1px;
height: 1px;
overflow: hidden;
opacity: 0;
pointer-events: none;
}
</style>