Lead Magnet Test

Some error text
Some error text
// Lead-magnet email verification hook — Selzy plugin edition // Drop into HFCM (Header Footer Code Manager) as a JavaScript snippet, placed in the Footer. // Targets the Selzy form shortcode [selzy-form id="..." title="..."]. // // How it works: // Selzy renders a
(not a real
). // The "submit" button is a
. // We intercept clicks on that div in the CAPTURE phase, verify the email // via our Zo Space API, then either block (bad email) or let it through (good email). (function () { const API_URL = "https://santisantiago.zo.space/api/verify-email"; const TIMEOUT_MS = 12000; function findSelzyForm() { // Selzy renders div.b-selzy-form (not a ) return document.querySelector("div.b-selzy-form"); } function findEmailInput(form) { return form.querySelector('input[name="email"], input[type="email"]'); } function findSubmitButton(form) { return form.querySelector(".b-selzy-form__submit-button"); } function findOrCreateErrorEl(form, emailInput) { // Selzy has its own error divs; use ours so the style is consistent let errorEl = form.querySelector(".lead-magnet-error"); if (!errorEl) { errorEl = document.createElement("div"); errorEl.className = "lead-magnet-error"; errorEl.setAttribute("role", "alert"); errorEl.setAttribute("aria-live", "polite"); errorEl.style.cssText = "color:#b00020;margin-top:10px;font-size:14px;line-height:1.4;"; // Insert after the email field's parent (the b-selzy-field div) const fieldWrapper = emailInput.closest(".b-selzy-field"); if (fieldWrapper) { fieldWrapper.insertAdjacentElement("afterend", errorEl); } else { emailInput.insertAdjacentElement("afterend", errorEl); } } return errorEl; } function arm() { const form = findSelzyForm(); if (!form) { console.warn("Lead-magnet hook: no Selzy form (div.b-selzy-form) found."); return; } // Kill Chrome's native validation — remove required/pattern from all fields // and add novalidate to the form element itself form.setAttribute("novalidate", ""); form.querySelectorAll("input, textarea, select").forEach((el) => { el.removeAttribute("required"); el.removeAttribute("pattern"); }); const emailInput = findEmailInput(form); if (!emailInput) { console.warn("Lead-magnet hook: email input not found in Selzy form."); return; } const submitBtn = findSubmitButton(form); if (!submitBtn) { console.warn("Lead-magnet hook: Selzy submit button not found."); return; } const errorEl = findOrCreateErrorEl(form, emailInput); const originalBtnText = submitBtn.textContent || "Subscribe"; // Intercept clicks in the CAPTURE phase so we run BEFORE Selzy's own handler submitBtn.addEventListener( "click", async function (e) { // If already verified, let Selzy's handler run normally if (form.__lmVerified === true) return; // Stop Selzy's handler from running e.stopPropagation(); e.preventDefault(); errorEl.textContent = ""; const email = (emailInput.value || "").trim(); if (!email) { errorEl.textContent = "Please enter your email address."; emailInput.focus(); return; } // Show verifying state submitBtn.style.opacity = "0.6"; submitBtn.style.pointerEvents = "none"; submitBtn.textContent = "Verifying…"; const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS); try { const res = await fetch(API_URL, { method: "POST", headers: { "Content-Type": "application/json", Accept: "application/json" }, body: JSON.stringify({ email }), signal: controller.signal, }); clearTimeout(timeoutId); const result = await res.json().catch(() => ({})); if (result.ok === true) { // Email verified — set flag and re-trigger the click // so Selzy's own handler picks it up form.__lmVerified = true; submitBtn.click(); return; } // Bad email — show error, restore button errorEl.textContent = result.message || result.error || "That email didn't look right — try a different one?"; emailInput.focus(); } catch (err) { clearTimeout(timeoutId); errorEl.textContent = "Email verification is taking too long. Please try again in a moment."; console.error("Lead-magnet verify error:", err); } finally { submitBtn.style.opacity = ""; submitBtn.style.pointerEvents = ""; submitBtn.textContent = originalBtnText; } }, true // CAPTURE phase — runs before Selzy's own listeners ); console.log("Lead-magnet hook: armed on Selzy form", form); } // Run once the form is in the DOM if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", arm); } else { arm(); } })();