diff --git a/index.html b/index.html index 4ce6a4a..5ae68e0 100644 --- a/index.html +++ b/index.html @@ -943,26 +943,26 @@
-
+
- +
- +
- +
- +
-
@@ -1128,25 +1128,67 @@ // ============================================ // FORM SUBMIT HANDLER // ============================================ - function handleSubmit() { - const button = event.target; - const originalText = button.innerHTML; + function initContactForm() { + const form = document.getElementById('contactForm'); + if (!form) return; - // Loading state - button.innerHTML = ' Sending...'; - button.disabled = true; - - setTimeout(() => { - button.innerHTML = '✓ Message Sent!'; - button.classList.remove('from-[#38BDF8]', 'to-[#A5B4FC]'); - button.style.background = '#22c55e'; + form.addEventListener('submit', async (e) => { + e.preventDefault(); - setTimeout(() => { - button.innerHTML = originalText; - button.disabled = false; - button.style.background = ''; - }, 2000); - }, 1500); + const button = form.querySelector('button[type="submit"]'); + const originalText = button.innerHTML; + + // Get form values + 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(); + + // Basic validation + if (!name || !email || !message) { + alert('Please fill in all required fields.'); + return; + } + + // Loading state + button.innerHTML = ' Sending...'; + button.disabled = true; + + try { + const response = await fetch('/api/contact', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ name, company, email, message }) + }); + + const data = await response.json(); + + if (data.success) { + button.innerHTML = '✓ Message Sent!'; + button.classList.remove('from-[#38BDF8]', 'to-[#A5B4FC]'); + button.style.background = '#22c55e'; + form.reset(); + + setTimeout(() => { + button.innerHTML = originalText; + button.disabled = false; + button.style.background = ''; + }, 3000); + } else { + throw new Error(data.message || 'Failed to send message'); + } + } 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); + } + }); } // ============================================ @@ -1210,6 +1252,7 @@ initTiltEffect(); initSmoothScroll(); animateCounters(); + initContactForm(); initAuth(); });