Lead form: flat urlencoded payload for Zoho Flow (Zoho wraps parsed body in its own payload var; browsers can't send application/json - no CORS on webhook). Pricing rolled into message (founders: message IS the pricing answers). New founders webhook URL.
This commit is contained in:
@@ -2,12 +2,15 @@
|
||||
// The lead form used by both audience pages. Labels come from the shared
|
||||
// per-locale strings; on submit a small fetch POSTs the payload to the
|
||||
// page's Zoho Flow webhook (token-in-URL authentication, no server code).
|
||||
// Deliberately minimal — the CRM only needs a name and an email; country
|
||||
// is deduced downstream from the submitted locale or the IP address.
|
||||
// The hubs variant carries a hidden "capabilities" field (set by the
|
||||
// capability checklist) and the founders variant a hidden "price_range"
|
||||
// field (set by the pricing checklist) — leads arrive in the CRM already
|
||||
// tagged with what interested them.
|
||||
// Deliberately minimal — the Flow's trigger parses the body into its own
|
||||
// "payload" variable, so the fields go FLAT: first_name, last_name, email,
|
||||
// consent (the CRM requires last_name). Browsers cannot send application/
|
||||
// json cross-origin to Zoho (no CORS headers on the webhook), so the form
|
||||
// posts application/x-www-form-urlencoded, which the trigger parses into
|
||||
// the same fields. There are no separate pricing fields: on the founders
|
||||
// page the pricing answers ARE the message; on the hubs page selections
|
||||
// are appended to the visitor's message. Country is deduced downstream
|
||||
// from the IP address.
|
||||
const { type: pageId, locale, strings, site } = Astro.props;
|
||||
// pageId arrives as the route id ("for-founders"/"for-support-organisations")
|
||||
// — normalise to the form kind:
|
||||
@@ -16,12 +19,14 @@ const type = pageId === "for-founders" ? "founders" : "hubs";
|
||||
const fields =
|
||||
type === "founders"
|
||||
? [
|
||||
{ name: "name", label: strings.field_name, input: "text", required: true },
|
||||
{ name: "first_name", label: strings.field_first_name, input: "text", required: true },
|
||||
{ name: "last_name", label: strings.field_last_name, input: "text", required: true },
|
||||
{ name: "email", label: strings.field_email, input: "email", required: true },
|
||||
]
|
||||
: [
|
||||
{ name: "organisation", label: strings.field_organisation, input: "text", required: true },
|
||||
{ name: "name", label: strings.field_name, input: "text", required: true },
|
||||
{ name: "first_name", label: strings.field_first_name, input: "text", required: true },
|
||||
{ name: "last_name", label: strings.field_last_name, input: "text", required: true },
|
||||
{ name: "email", label: strings.field_email, input: "email", required: true },
|
||||
{ name: "message", label: strings.field_message, input: "textarea" },
|
||||
];
|
||||
@@ -71,11 +76,7 @@ const note = type === "founders" ? strings.form_founders_note : strings.form_hub
|
||||
autocomplete="off"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<input type="hidden" name="capabilities" value="" />
|
||||
<input type="hidden" name="price_range" value="" />
|
||||
<input type="hidden" name="price_model" value="" />
|
||||
<input type="hidden" name="locale" value={locale} />
|
||||
<input type="hidden" name="source" value={type} />
|
||||
<label class="consent">
|
||||
<input type="checkbox" name="consent" required />
|
||||
<span>{strings.form_consent}</span>
|
||||
@@ -93,12 +94,10 @@ const note = type === "founders" ? strings.form_founders_note : strings.form_hub
|
||||
};
|
||||
|
||||
// CHECKLISTS above the form (capabilities on the hubs page, the
|
||||
// four price questions on the founders page): collect the checked
|
||||
// boxes at submit time so each selection rides the payload — machine
|
||||
// keys joined as group=option pairs for prices, and a human-readable
|
||||
// echo per checklist mirrors the live selection back to the visitor.
|
||||
// four price questions on the founders page): mirror the live
|
||||
// selection back to the visitor; at submit time the checked boxes
|
||||
// are read straight from the DOM into the message text.
|
||||
const collect = (attrName, containerId) => {
|
||||
const field = form.querySelector(`input[name="${attrName === "data-cap" ? "capabilities" : "price_range"}"]`);
|
||||
const echo = document.getElementById(containerId);
|
||||
const key = (c) =>
|
||||
attrName === "data-cap"
|
||||
@@ -112,7 +111,6 @@ const note = type === "founders" ? strings.form_founders_note : strings.form_hub
|
||||
.join(", ");
|
||||
echo.hidden = !checked.length;
|
||||
}
|
||||
if (field) field.value = checked.map(key).join(",");
|
||||
};
|
||||
document.querySelectorAll(`[${attrName}]`).forEach((el) => {
|
||||
el.addEventListener("change", refresh);
|
||||
@@ -126,34 +124,42 @@ const note = type === "founders" ? strings.form_founders_note : strings.form_hub
|
||||
event.preventDefault();
|
||||
const button = form.querySelector('button[type="submit"]');
|
||||
const data = new FormData(form);
|
||||
const payload = {};
|
||||
data.forEach((v, k) => { payload[k] = v; });
|
||||
// consent as a JSON boolean (the Flow/CRM mapping expects true/false,
|
||||
// not the checkbox's literal "on"; an unchecked box never arrives)
|
||||
payload.consent = data.get("consent") === "on";
|
||||
if (payload.website) return; // honeypot: pretend success, send nothing
|
||||
// The pricing-model picker sits outside the <form>; it is mirrored
|
||||
// into the hidden price_model input on change, so FormData carries it.
|
||||
// On top of the machine fields, concat every tracked selection into
|
||||
// the message: Zoho Flow reliably maps the standard fields only, and
|
||||
// this way nothing is lost in field mapping.
|
||||
if (data.get("website")) return; // honeypot: pretend success, send nothing
|
||||
// The Flow's trigger parses the body into its own "payload" variable,
|
||||
// so the fields go FLAT (last_name is required by the CRM); consent
|
||||
// as "true"/"false", not the checkbox's literal "on".
|
||||
const payload = {
|
||||
first_name: data.get("first_name"),
|
||||
last_name: data.get("last_name"),
|
||||
email: data.get("email"),
|
||||
consent: String(data.get("consent") === "on"),
|
||||
};
|
||||
if (form.dataset.type === "hubs") payload.organisation = data.get("organisation");
|
||||
// No separate pricing fields: on the founders page the pricing
|
||||
// answers ARE the message; on the hubs page selections are appended
|
||||
// to the visitor's message so nothing is lost in field mapping.
|
||||
const lines = [];
|
||||
const capLabels = [...document.querySelectorAll("[data-cap]:checked")]
|
||||
.map((c) => c.dataset.capLabel || c.dataset.cap);
|
||||
if (capLabels.length) lines.push("Selected features: " + capLabels.join(", "));
|
||||
if (payload.price_model) lines.push("Pricing model: " + payload.price_model);
|
||||
const priceModel = data.get("price_model");
|
||||
if (priceModel) lines.push("Pricing model: " + priceModel);
|
||||
const pricePairs = [...document.querySelectorAll("[data-price]:checked")]
|
||||
.map((c) => c.dataset.priceGroup + " = " + c.dataset.priceLabel);
|
||||
if (pricePairs.length) lines.push("Price answers: " + pricePairs.join("; "));
|
||||
if (lines.length) payload.message = (payload.message ? payload.message + "\n\n" : "") + lines.join("\n");
|
||||
const baseMessage = data.get("message") || "";
|
||||
const extras = lines.join("\n");
|
||||
if (extras || baseMessage) {
|
||||
payload.message = baseMessage + (baseMessage && extras ? "\n\n" : "") + extras;
|
||||
}
|
||||
button.disabled = true;
|
||||
button.textContent = STRINGS.sending || "Sending…";
|
||||
try {
|
||||
await fetch(form.dataset.webhook, {
|
||||
method: "POST",
|
||||
mode: "no-cors", // tell the browser we don't need to read the response
|
||||
headers: { "Content-Type": "text/plain;charset=UTF-8" }, // no preflight triggered
|
||||
body: JSON.stringify(payload),
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded" }, // no preflight, and Zoho parses the fields
|
||||
body: new URLSearchParams(payload).toString(),
|
||||
});
|
||||
form.innerHTML = '<p class="lead-ok"></p>';
|
||||
form.querySelector(".lead-ok").textContent = form.dataset.i18nSuccess;
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
"app_url": "https://app.validationlab.eu",
|
||||
"base_url": "https://validationlab.eu",
|
||||
"contact_email": "hello@app.validationlab.eu",
|
||||
"zoho_webhook_founders": "https://flow.zoho.eu/20063218454/flow/webhook/incoming?zapikey=1001.6a505b889bf2068a637ccf35a089dd13.03042518edd586c91f90a30e8a372953&isdebug=true",
|
||||
"zoho_webhook_founders": "https://flow.zoho.eu/20063218454/flow/webhook/incoming?zapikey=1001.c6bc317652bec8c53980971c6f9c2902.de27f6229b7b1cf89d14a9f931eb4b8e&isdebug=true",
|
||||
"zoho_webhook_hubs": "https://flow.zoho.eu/20063218454/flow/webhook/incoming?zapikey=1001.58704c9ef39b6f155b6220a8db49ff40.4052a48932209ece41e644e4f49e0ce0&isdebug=false",
|
||||
"stats_script_url": "https://stats.iwrote.it/script.js",
|
||||
"stats_website_id": "ac5736ad-a766-4698-9730-15ed8fe343df"
|
||||
|
||||
+2
-1
@@ -25,7 +25,8 @@
|
||||
"form_founders_note": "Leave your name and email - we'll send your invitation within a few days.",
|
||||
"form_hubs_title": "Talk to us about your organisation",
|
||||
"form_hubs_note": "No long forms, no survey - the features you ticked above arrive with your message.",
|
||||
"field_name": "Your name",
|
||||
"field_first_name": "First name",
|
||||
"field_last_name": "Last name",
|
||||
"field_organisation": "Organisation",
|
||||
"field_email": "Email",
|
||||
"field_message": "Message (optional)"
|
||||
|
||||
+2
-1
@@ -25,7 +25,8 @@
|
||||
"form_founders_note": "Lascia il tuo nome e il tuo indirizzo e-mail: ti invieremo l'invito entro pochi giorni.",
|
||||
"form_hubs_title": "Raccontaci della tua organizzazione",
|
||||
"form_hubs_note": "Niente moduli lunghi, niente sondaggi: le opzioni che hai selezionato sopra vengono allegate al tuo messaggio.",
|
||||
"field_name": "Il tuo nome",
|
||||
"field_first_name": "Nome",
|
||||
"field_last_name": "Cognome",
|
||||
"field_organisation": "Organizzazione",
|
||||
"field_email": "E-mail",
|
||||
"field_message": "Messaggio (facoltativo)"
|
||||
|
||||
+2
-1
@@ -25,7 +25,8 @@
|
||||
"form_founders_note": "Ħalli l-isem u l-indirizz elettroniku tiegħek - se nibgħatulek l-istedina fi ftit jiem.",
|
||||
"form_hubs_title": "Tkellem magħna dwar l-organizzazzjoni tiegħek",
|
||||
"form_hubs_note": "L-ebda formoli twal, l-ebda stħarriġ – il-karatteristiċi li għażilt hawn fuq jaslu mal-messaġġ tiegħek.",
|
||||
"field_name": "Ismek",
|
||||
"field_first_name": "L-ewwel isem",
|
||||
"field_last_name": "Kunjom",
|
||||
"field_organisation": "Organizzazzjoni",
|
||||
"field_email": "Email",
|
||||
"field_message": "Messaġġ (mhux obbligatorju)"
|
||||
|
||||
@@ -429,9 +429,7 @@ const hasForm = isAudiencePage;
|
||||
const mirror = document.querySelector('form input[name="price_model"]');
|
||||
if (mirror) mirror.value = model;
|
||||
// programmatic unchecking fires no change event - clear the
|
||||
// hidden payload field and its echo by hand
|
||||
const pr = document.querySelector('form input[name="price_range"]');
|
||||
if (pr) pr.value = "";
|
||||
// echo by hand
|
||||
const echo = document.getElementById("price-selection");
|
||||
if (echo) { echo.textContent = ""; echo.hidden = true; }
|
||||
if (groups[0]) {
|
||||
|
||||
Reference in New Issue
Block a user