From 93f6dd14b0e177e7995742b88c93bb0c0d6f8652 Mon Sep 17 00:00:00 2001 From: Thomas Smith <49042513+tsmitty11@users.noreply.github.com> Date: Tue, 7 Feb 2023 18:59:50 -0500 Subject: [PATCH] Benchmark --- src/layouts/partials/mobile-ctas.html | 89 ++++++++++++++------------- 1 file changed, 45 insertions(+), 44 deletions(-) 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.

'; + }); + }); +