var contactUsPrefix = "contact-us-"; var contactUsForm = document.getElementById(contactUsPrefix + "form"); function handleContactUsForm(event) { event.preventDefault(); var name = document.getElementById(contactUsPrefix + "name").value; var phone = document.getElementById(contactUsPrefix + "phone").value; var email = document.getElementById(contactUsPrefix + "email").value; var message = document.getElementById(contactUsPrefix + "message").value; if (phone || email) { fetch("https://txwfnjydfk7enq3s337qi2vcn40kwpgf.lambda-url.us-east-2.on.aws/", { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json", }, body: JSON.stringify({ name: name, phone: phone, email: email, message: message, type: "Contact_Us", }), }) .then((response) => { // console.log(response); showSnackbar("Thank you for contacting us, we'll be in touch very soon") document.getElementById(contactUsPrefix + "name").value = ''; document.getElementById(contactUsPrefix + "phone").value = ''; document.getElementById(contactUsPrefix + "email").value = ''; document.getElementById(contactUsPrefix + "message").value = ''; }) .catch((err) => { // console.log(err); showSnackbar("Thank you for contacting us, we'll be in touch very soon") document.getElementById(contactUsPrefix + "name").value = ''; document.getElementById(contactUsPrefix + "phone").value = ''; document.getElementById(contactUsPrefix + "email").value = ''; document.getElementById(contactUsPrefix + "message").value = ''; }); } } contactUsForm.addEventListener("submit", handleContactUsForm); var subscribeForm = document.getElementById("subscribe-form"); function handleSubscribeForm(event) { event.preventDefault(); var email = document.getElementById("subscribe-email").value; if (email) { fetch("https://txwfnjydfk7enq3s337qi2vcn40kwpgf.lambda-url.us-east-2.on.aws/", { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json", }, body: JSON.stringify({ email: email, type: "Subscribe", }), }) .then((response) => { // console.log(response); showSnackbar('Thank you for subscribing to our newsletter') document.getElementById("subscribe-email").value = ''; }) .catch((err) => { // console.log(err); showSnackbar('Thank you for subscribing to our newsletter') document.getElementById("subscribe-email").value = ''; }); } } subscribeForm.addEventListener("submit", handleSubscribeForm); function showSnackbar(message) { // Get the snackbar DIV var snackbar = document.getElementById("snackbar"); snackbar.textContent = message; // Add the "show" class to DIV snackbar.className = "show"; // After 3 seconds, remove the show class from DIV setTimeout(function(){ snackbar.className = snackbar.className.replace("show", ""); }, 3000); }