document.addEventListener('DOMContentLoaded', () => { const joinForm = document.getElementById('joinForm'); if (joinForm) { joinForm.addEventListener('submit', async (e) => { e.preventDefault(); const submitBtn = joinForm.querySelector('button[type="submit"]'); const originalText = submitBtn.innerText; submitBtn.disabled = true; submitBtn.innerText = 'Joining...'; const formData = new FormData(joinForm); try { const response = await fetch('join_community.php', { method: 'POST', body: formData }); const result = await response.json(); if (result.success) { showToast('Welcome to the Pit Wall! 🎉'); joinForm.reset(); // Optional: Refresh member list or redirect setTimeout(() => location.reload(), 1500); } else { showToast('Error: ' + result.error, 'danger'); } } catch (error) { showToast('Something went wrong. Please try again.', 'danger'); } finally { submitBtn.disabled = false; submitBtn.innerText = originalText; } }); } }); function showToast(message, type = 'success') { const toastContainer = document.getElementById('toastContainer'); const toastHtml = `