document.addEventListener('DOMContentLoaded', function () { const inviteForm = document.getElementById('invite-form'); if (inviteForm) { inviteForm.addEventListener('submit', function (e) { e.preventDefault(); const email = document.getElementById('email').value; const formData = new FormData(); formData.append('email', email); fetch('request_invite.php', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { showToast(data.message, data.success ? 'success' : 'error'); if (data.success) { inviteForm.reset(); } }) .catch(error => { showToast('An unexpected error occurred.', 'error'); console.error('Error:', error); }); }); } function showToast(message, type) { const toastContainer = document.getElementById('toast-container'); if (!toastContainer) return; const toast = document.createElement('div'); toast.className = `toast align-items-center text-white bg-${type === 'success' ? 'success' : 'danger'} border-0 show`; toast.setAttribute('role', 'alert'); toast.setAttribute('aria-live', 'assertive'); toast.setAttribute('aria-atomic', 'true'); const toastBody = document.createElement('div'); toastBody.className = 'd-flex'; toastBody.innerHTML = `
${message}
`; toast.appendChild(toastBody); toastContainer.appendChild(toast); const bsToast = new bootstrap.Toast(toast); bsToast.show(); setTimeout(() => { bsToast.hide(); setTimeout(() => toast.remove(), 500); }, 5000); } document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); document.querySelector(this.getAttribute('href')).scrollIntoView({ behavior: 'smooth' }); }); }); });