59 lines
2.7 KiB
JavaScript
59 lines
2.7 KiB
JavaScript
document.addEventListener('DOMContentLoaded', function () {
|
|
const waitlistForm = document.getElementById('waitlistForm');
|
|
const toastEl = document.getElementById('liveToast');
|
|
const toastBody = toastEl.querySelector('.toast-body');
|
|
const toast = new bootstrap.Toast(toastEl);
|
|
|
|
if (waitlistForm) {
|
|
waitlistForm.addEventListener('submit', function (e) {
|
|
e.preventDefault();
|
|
const emailInput = document.getElementById('email');
|
|
const email = emailInput.value;
|
|
|
|
if (!email || !/^\S+@\S+\.\S+$/.test(email)) {
|
|
toastBody.textContent = 'Please enter a valid email address.';
|
|
toastBody.parentElement.classList.remove('bg-success', 'text-white');
|
|
toastBody.parentElement.classList.add('bg-danger', 'text-white');
|
|
toast.show();
|
|
return;
|
|
}
|
|
|
|
const submitButton = waitlistForm.querySelector('button[type="submit"]');
|
|
submitButton.disabled = true;
|
|
submitButton.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Sending...';
|
|
|
|
fetch('join_waitlist.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
},
|
|
body: 'email=' + encodeURIComponent(email)
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
toastBody.textContent = data.message || 'Thanks for joining the waitlist!';
|
|
toastBody.parentElement.classList.remove('bg-danger', 'text-white');
|
|
toastBody.parentElement.classList.add('bg-success', 'text-white');
|
|
emailInput.value = '';
|
|
} else {
|
|
toastBody.textContent = data.message || 'Something went wrong. Please try again.';
|
|
toastBody.parentElement.classList.remove('bg-success', 'text-white');
|
|
toastBody.parentElement.classList.add('bg-danger', 'text-white');
|
|
}
|
|
toast.show();
|
|
})
|
|
.catch(error => {
|
|
toastBody.textContent = 'An error occurred. Please try again later.';
|
|
toastBody.parentElement.classList.remove('bg-success', 'text-white');
|
|
toastBody.parentElement.classList.add('bg-danger', 'text-white');
|
|
toast.show();
|
|
})
|
|
.finally(() => {
|
|
submitButton.disabled = false;
|
|
submitButton.textContent = 'Notify Me';
|
|
});
|
|
});
|
|
}
|
|
});
|