diff --git a/src/layouts/partials/mobile-ctas.html b/src/layouts/partials/mobile-ctas.html index 9cf2bdb..e6d8776 100644 --- a/src/layouts/partials/mobile-ctas.html +++ b/src/layouts/partials/mobile-ctas.html @@ -42,51 +42,52 @@ } - - - + const subscribeForm = document.getElementById("subscribeForm"); + const formResponse = document.getElementById("formResponse"); + + subscribeForm.addEventListener("submit", event => { + event.preventDefault(); + + const email = document.getElementById("email").value; + + if (!email) { + formResponse.innerHTML = + '

Please enter a valid email address.

'; + return; + } + + fetch("https://manage.klaviyo.com/api/v1/list/R2UVm3/members", { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ + email: email, + api_key: "pk_231a258e61a40283566192ee59310c7af4" + }) + }) + .then(response => { + if (!response.ok) { + throw new Error("Failed to subscribe"); + } + formResponse.innerHTML = + '

Form submitted!

'; + }) + .catch(error => { + formResponse.innerHTML = + '

An error occurred. Please try again later.

'; + }); + }); +