From bd4919ff4bf44e89edc391e04267ce782b9c6c69 Mon Sep 17 00:00:00 2001 From: Moxiegen Admin Date: Sat, 2 May 2026 20:53:04 +0000 Subject: [PATCH] Switch contact form to FormSubmit.co - Replace /api/contact POST with FormSubmit.co action - Add honeypot anti-spam, success banner, FormData handler --- index.html | 88 ++++++++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 49 deletions(-) diff --git a/index.html b/index.html index c7b2b99..00e120a 100644 --- a/index.html +++ b/index.html @@ -267,29 +267,47 @@
-
+ +
- +
- +
+
- +
+
- +
-
+ + +
@@ -502,63 +520,35 @@ } // ============================================ - // FORM SUBMIT HANDLER + // FORM SUBMIT HANDLER (FormSubmit.co) // ============================================ function initContactForm() { - const form = document.getElementById('contactForm'); - if (!form) return; - - form.addEventListener('submit', async (e) => { + const form = document.getElementById('contact-form'); + const successDiv = document.getElementById('success-message'); + + form.addEventListener('submit', async function(e) { e.preventDefault(); - const button = form.querySelector('button[type="submit"]'); - const originalText = button.innerHTML; - - const name = document.getElementById('contactName').value.trim(); - const company = document.getElementById('contactCompany').value.trim(); - const email = document.getElementById('contactEmail').value.trim(); - const message = document.getElementById('contactMessage').value.trim(); - - if (!name || !email || !message) { - alert('Please fill in all required fields.'); - return; - } - - button.innerHTML = ' Sending...'; - button.disabled = true; + const formData = new FormData(form); try { - const response = await fetch('/api/contact', { + const response = await fetch(form.action, { method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ name, company, email, message }) + body: formData }); - - const data = await response.json(); - - if (data.success) { - button.innerHTML = '✓ Message Sent!'; - button.style.background = '#22c55e'; + + if (response.ok) { + successDiv.classList.remove('hidden'); form.reset(); setTimeout(() => { - button.innerHTML = originalText; - button.disabled = false; - button.style.background = ''; - }, 3000); + successDiv.classList.add('hidden'); + }, 6000); } else { - throw new Error(data.message || 'Failed to send message'); + alert('Something went wrong. Please try again.'); } } catch (error) { - console.error('Contact form error:', error); - button.innerHTML = '✗ Failed to send'; - button.style.background = '#ef4444'; - - setTimeout(() => { - button.innerHTML = originalText; - button.disabled = false; - button.style.background = ''; - }, 3000); + alert('Network error. Please check your connection and try again.'); } }); }