From 1ce0a12618fa5a4e07bbac7997b403d83421347b Mon Sep 17 00:00:00 2001 From: Z User Date: Mon, 19 Oct 2026 18:18:44 +0000 Subject: [PATCH] Add confirmation modal + honeypot to contact form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Submit now opens a 'Confirm your message' review dialog (reuses the site's dl-modal styles) showing name/company/email/message for a final check before anything is sent - Confirm & send performs the actual POST; Go back & edit / X / overlay click / Escape all return to the form with values intact - Extra bot defenses: hidden honeypot field (name=website) and a 2-second time-trap — bots that trip either get a fake success message and nothing is sent to the API - Payload to /api/contact unchanged --- index.html | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 125 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index bba6bb7..5c3d2a0 100755 --- a/index.html +++ b/index.html @@ -774,6 +774,45 @@ margin-left: auto; } } + + .cf-review { + display: flex; + flex-direction: column; + gap: 14px; + background: rgba(2, 6, 23, 0.6); + border: 1px solid rgba(148, 163, 184, 0.15); + border-radius: 1.25rem; + padding: 1.5rem; + } + + .cf-row { + display: flex; + flex-direction: column; + gap: 2px; + } + + .cf-label { + font-size: 0.7rem; + font-weight: 600; + text-transform: uppercase; + letter-spacing: 0.12em; + color: #64748b; + } + + .cf-value { + color: #e2e8f0; + font-size: 1rem; + overflow-wrap: anywhere; + } + + .hp-field { + position: absolute !important; + left: -9999px !important; + width: 1px !important; + height: 1px !important; + opacity: 0 !important; + pointer-events: none !important; + } @@ -1074,6 +1113,8 @@
+
@@ -1112,6 +1153,42 @@
+ +
+
+
+
+

+ Confirm your message

+

Quick check before it goes out — + everything look right?

+
+ +
+
+
+
Name
+
Company
+
Email
+
Message
+
+
+ + +
+
+
+
+
@@ -2103,10 +2180,31 @@ } } + let cfPendingData = null; + + function openConfirmModal() { + document.getElementById('confirmModal').classList.add('active'); + document.body.style.overflow = 'hidden'; + } + + function closeConfirmModal() { + document.getElementById('confirmModal').classList.remove('active'); + document.body.style.overflow = ''; + } + function initContactForm() { const form = document.getElementById('contact-form'); const successDiv = document.getElementById('success-message'); - form.addEventListener('submit', async function (e) { + let formLoadedAt = Date.now(); + + const showSuccess = () => { + successDiv.classList.remove('hidden'); + form.reset(); + formLoadedAt = Date.now(); + setTimeout(() => { successDiv.classList.add('hidden'); }, 6000); + }; + + form.addEventListener('submit', function (e) { e.preventDefault(); const data = { name: form.name.value.trim(), @@ -2115,7 +2213,25 @@ message: form.message.value.trim() }; if (!data.name || !data.email || !data.message) { alert('Please fill in all required fields.'); return; } - const btn = form.querySelector('button[type="submit"]'); + + // Anti-bot: honeypot + time-trap. Humans never fill the hidden field + // and never submit in under 2s — bots that do get a fake success, nothing is sent. + const honeypot = form.website ? form.website.value.trim() : ''; + if (honeypot || (Date.now() - formLoadedAt) < 2000) { showSuccess(); return; } + + cfPendingData = data; + document.getElementById('cf-name').textContent = data.name; + document.getElementById('cf-company').textContent = data.company || '—'; + document.getElementById('cf-email').textContent = data.email; + document.getElementById('cf-message').textContent = data.message; + openConfirmModal(); + document.getElementById('cf-send-btn').focus(); + }); + + document.getElementById('cf-send-btn').addEventListener('click', async function () { + if (!cfPendingData) return; + const data = cfPendingData; + const btn = this; const originalText = btn.textContent; btn.disabled = true; btn.textContent = 'Sending...'; try { @@ -2124,11 +2240,15 @@ }); const result = await response.json(); if (response.ok && result.success) { - successDiv.classList.remove('hidden'); form.reset(); - setTimeout(() => { successDiv.classList.add('hidden'); }, 6000); + closeConfirmModal(); + showSuccess(); } else { alert(result.message || 'Something went wrong. Please try again.'); } } catch (error) { alert('Network error. Please check your connection and try again.'); } - finally { btn.disabled = false; btn.textContent = originalText; } + finally { btn.disabled = false; btn.textContent = originalText; cfPendingData = null; } + }); + + document.addEventListener('keydown', (e) => { + if (e.key === 'Escape' && document.getElementById('confirmModal').classList.contains('active')) closeConfirmModal(); }); }