// ── STEP 1: Replace these three values ──────────────────────────
const WEB3FORMS_KEY = “YOUR_WEB3FORMS_KEY”; // from web3forms.com
const CC_ACCESS_TOKEN = “YOUR_CC_ACCESS_TOKEN”; // Constant Contact API token
const CC_LIST_ID = “YOUR_CC_LIST_ID”; // Constant Contact list ID
// ────────────────────────────────────────────────────────────────
// ── FORM HTML (replaces the
*/
// ── bindResultHandlers (replaces existing function) ──────────────
function bindResultHandlers(){
$(“[data-act=’restart’]”)?.addEventListener(“click”, () => {
for (const k in answers) delete answers[k];
step = 0; scores = { o:0 };
render();
});
$(“[data-act=’print’]”)?.addEventListener(“click”, () => window.print());
const form = document.getElementById(“iw-lead”);
const msg = document.getElementById(“iw-msg”);
form?.addEventListener(“submit”, async (e) => {
e.preventDefault();
msg.textContent = “”;
const name = document.getElementById(“iw-name”).value.trim();
const email = document.getElementById(“iw-email”).value.trim();
const phone = document.getElementById(“iw-phone”).value.trim();
const agree = document.getElementById(“iw-agree”).checked;
if (!name || !email || !phone){ msg.textContent=”Please complete all fields.”; return; }
if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email)){ msg.textContent=”Please enter a valid email.”; return; }
if (!agree){ msg.textContent=”Please confirm consent to be contacted.”; return; }
const btn = form.querySelector(“button[type=submit]”);
btn.disabled = true;
msg.textContent = “Sending…”;
let ccOk = false, notifyOk = false;
// ── 1. Add to Constant Contact ───────────────────────────────
try {
const ccRes = await fetch(“https://api.cc.email/v3/contacts”, {
method: “POST”,
headers: {
“Content-Type”: “application/json”,
“Authorization”: “Bearer ” + CC_ACCESS_TOKEN
},
body: JSON.stringify({
email_address: { address: email, permission_to_send: “implicit” },
first_name: name.split(” “)[0],
last_name: name.split(” “).slice(1).join(” “) || “”,
phone_numbers: [{ phone_number: phone, kind: “mobile” }],
list_memberships: [ CC_LIST_ID ],
create_source: “Contact”
})
});
ccOk = ccRes.ok || ccRes.status === 409; // 409 = already exists, that’s fine
} catch(err) {
console.error(“CC error:”, err);
}
// ── 2. Send notification to clinic via Web3Forms ─────────────
try {
const notifyRes = await fetch(“https://api.web3forms.com/submit”, {
method: “POST”,
headers: { “Content-Type”: “application/json” },
body: JSON.stringify({
access_key: WEB3FORMS_KEY,
subject: “New O-Shot Self-Test Lead”,
from_name: “O-Shot Self-Test”,
name,
email,
phone,
oshot_score: scores.o,
page: window.location.href,
message: “New lead from the O-Shot self-test on your website.”
})
});
const notifyData = await notifyRes.json();
notifyOk = notifyData.success;
} catch(err) {
console.error(“Web3Forms error:”, err);
}
btn.disabled = false;
if (ccOk || notifyOk) {
msg.innerHTML = ‘Thank you! We will be in touch soon. You can also text INTIMATE to 770-649-0094 anytime.‘;
form.reset();
} else {
msg.textContent = “Something went wrong. Please text us at 770-649-0094.”;
}
});
}
