/** * Contact Form Handler using Web3Forms * Sends emails to: connect@seva-innovations.com * * SETUP: * 1. Go to https://web3forms.com/ * 2. Enter: connect@seva-innovations.com * 3. Verify your email * 4. Copy the Access Key * 5. Replace YOUR_WEB3FORMS_KEY in Index.html with your key */ (function() { 'use strict'; // Initialize when DOM is ready document.addEventListener('DOMContentLoaded', function() { initContactForm(); initSmoothScrolling(); initNavbarScroll(); }); function initContactForm() { var form = document.getElementById('form'); var result = document.getElementById('result'); if (!form) { console.log('Contact form not found on this page'); return; } form.addEventListener('submit', function(e) { e.preventDefault(); // Check for access key (admin SiteContent > SevaConfig > form input, in that order) var accessKeyInput = form.querySelector('input[name="access_key"]'); var adminIntegrations = (typeof SiteContent !== 'undefined' && SiteContent.get) ? SiteContent.get('integrations') : null; var accessKey = (adminIntegrations && adminIntegrations.web3formsAccessKey) || (typeof SevaConfig !== 'undefined' && SevaConfig.WEB3FORMS ? SevaConfig.WEB3FORMS.accessKey : null) || (accessKeyInput ? accessKeyInput.value : null); if (accessKeyInput && accessKey) accessKeyInput.value = accessKey; if (!accessKey || accessKey === 'YOUR_WEB3FORMS_KEY') { showResult('warning', 'Contact form not configured. Please set up Web3Forms access key.'); console.error('Web3Forms access key not configured. See config.js WEB3FORMS.'); return; } // Ensure access_key is in form data (inject if from config) if (!accessKeyInput && accessKey) { var hidden = document.createElement('input'); hidden.type = 'hidden'; hidden.name = 'access_key'; hidden.value = accessKey; form.appendChild(hidden); } // Get form data var formData = new FormData(form); var object = Object.fromEntries(formData); var json = JSON.stringify(object); // Show loading state showResult('info', 'Sending your message...'); // Disable submit button var submitBtn = form.querySelector('button[type="submit"]'); var originalText = submitBtn.innerHTML; submitBtn.innerHTML = 'Sending...'; submitBtn.disabled = true; // Send to Web3Forms fetch('https://api.web3forms.com/submit', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: json }) .then(function(response) { return response.json().then(function(data) { return { ok: response.ok, data: data }; }); }) .then(function(result) { if (result.ok) { var recipient = (adminIntegrations && adminIntegrations.web3formsRecipient) || (typeof SevaConfig !== 'undefined' && SevaConfig.WEB3FORMS ? SevaConfig.WEB3FORMS.recipientEmail : null) || 'connect@seva-innovations.com'; showResult('success', 'Thank you! Your message has been sent to ' + recipient + '. We\'ll get back to you soon.'); form.reset(); } else { showResult('warning', '' + (result.data.message || 'Something went wrong. Please try again.')); } }) .catch(function(error) { console.error('Form submission error:', error); showResult('danger', 'Network error. Please check your connection and try again.'); }) .finally(function() { // Re-enable submit button submitBtn.innerHTML = originalText; submitBtn.disabled = false; }); }); // Add input validation feedback var inputs = form.querySelectorAll('input[required], textarea[required]'); inputs.forEach(function(input) { input.addEventListener('blur', function() { if (!this.value.trim()) { this.classList.add('is-invalid'); this.classList.remove('is-valid'); } else { this.classList.remove('is-invalid'); this.classList.add('is-valid'); } }); input.addEventListener('input', function() { if (this.classList.contains('is-invalid') && this.value.trim()) { this.classList.remove('is-invalid'); } }); }); function showResult(type, message) { if (!result) return; result.className = 'alert alert-' + type + ' mt-3'; result.innerHTML = message; result.style.display = 'block'; // Auto-hide success/info messages if (type === 'success') { setTimeout(function() { result.style.display = 'none'; }, 8000); } } } // Smooth scrolling for anchor links function initSmoothScrolling() { document.querySelectorAll('a[href^="#"]').forEach(function(anchor) { anchor.addEventListener('click', function(e) { var targetId = this.getAttribute('href'); if (targetId === '#') return; var target = document.querySelector(targetId); if (target) { e.preventDefault(); target.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }); }); } // Navbar background on scroll function initNavbarScroll() { var navbar = document.querySelector('.navbar'); if (!navbar) return; function updateNavbar() { if (window.scrollY > 50) { navbar.classList.add('bg-white', 'shadow'); } else { navbar.classList.remove('bg-white', 'shadow'); } } window.addEventListener('scroll', updateNavbar); updateNavbar(); // Initial check } })();