156 lines
6.3 KiB
Plaintext
156 lines
6.3 KiB
Plaintext
---
|
|
// 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).
|
|
// The hubs variant carries a hidden "capabilities" field the capability
|
|
// blocks on the landing page append to when clicked — leads arrive in the
|
|
// CRM already tagged with what interested them.
|
|
const { type: pageId, locale, strings, site } = Astro.props;
|
|
// pageId arrives as the route id ("for-founders"/"for-innovation-hubs")
|
|
// — normalise to the form kind:
|
|
const type = pageId === "for-founders" ? "founders" : "hubs";
|
|
|
|
const fields =
|
|
type === "founders"
|
|
? [
|
|
{ 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: "stage", label: strings.field_stage, input: "select", options: [
|
|
["idea", strings.field_stage_idea],
|
|
["prototype", strings.field_stage_prototype],
|
|
["launch", strings.field_stage_launch],
|
|
] },
|
|
{ name: "sector", label: strings.field_sector, input: "text" },
|
|
{ name: "country", label: strings.field_country, input: "text" },
|
|
{ name: "heard", label: strings.field_heard, input: "text" },
|
|
]
|
|
: [
|
|
{ name: "organisation", label: strings.field_organisation, 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: "country", label: strings.field_country, input: "text" },
|
|
{ name: "programme", label: strings.field_programme, input: "select", options: [
|
|
["incubator", strings.field_programme_incubator],
|
|
["accelerator", strings.field_programme_accelerator],
|
|
["edih", strings.field_programme_edih],
|
|
["een", strings.field_programme_een],
|
|
["agency", strings.field_programme_agency],
|
|
["other", strings.field_programme_other],
|
|
] },
|
|
{ name: "message", label: strings.field_message, input: "textarea" },
|
|
];
|
|
|
|
const webhook =
|
|
type === "founders" ? site.zoho_webhook_founders : site.zoho_webhook_hubs;
|
|
const title = type === "founders" ? strings.form_founders_title : strings.form_hubs_title;
|
|
const note = type === "founders" ? strings.form_founders_note : strings.form_hubs_note;
|
|
---
|
|
<section class="lead-wrap">
|
|
<form
|
|
id="lead-form"
|
|
class="lead"
|
|
data-webhook={webhook}
|
|
data-sending-label={strings.form_sending}
|
|
data-locale={locale}
|
|
data-type={type}
|
|
data-i18n-success={strings.form_success}
|
|
data-i18n-error={strings.form_error}
|
|
data-contact-email={site.contact_email}
|
|
>
|
|
<h2 id="lead-form">{title}</h2>
|
|
<p class="lead-note">{note}</p>
|
|
{fields.map((f) => (
|
|
<label>
|
|
{f.label}{f.required ? " *" : ""}
|
|
{f.input === "select" ? (
|
|
<select name={f.name} required={f.required ?? false}>
|
|
{f.options.map(([value, label]) => (
|
|
<option value={value}>{label}</option>
|
|
))}
|
|
</select>
|
|
) : f.input === "textarea" ? (
|
|
<textarea name={f.name} required={f.required ?? false}></textarea>
|
|
) : (
|
|
<input type={f.input} name={f.name} required={f.required ?? false} />
|
|
)}
|
|
</label>
|
|
))}
|
|
<input
|
|
class="hp"
|
|
type="text"
|
|
name="website"
|
|
tabindex="-1"
|
|
autocomplete="off"
|
|
aria-hidden="true"
|
|
/>
|
|
<input type="hidden" name="capabilities" 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>
|
|
</label>
|
|
<button class="button" type="submit">{strings.form_send}</button>
|
|
</form>
|
|
<script is:inline>
|
|
(() => {
|
|
const form = document.getElementById("lead-form");
|
|
if (!form || form.dataset.bound) return;
|
|
form.dataset.bound = "1";
|
|
|
|
const STRINGS = {
|
|
sending: form.dataset.sendingLabel,
|
|
};
|
|
|
|
// capability blocks tag the form (analyst clicks are separate, via
|
|
// data-umami-event attributes on the block links)
|
|
const capField = form.querySelector('input[name="capabilities"]');
|
|
document.querySelectorAll("[data-cap]").forEach((el) => {
|
|
el.addEventListener("click", () => {
|
|
if (!capField.value.split(",").includes(el.dataset.cap)) {
|
|
capField.value = capField.value
|
|
? capField.value + "," + el.dataset.cap
|
|
: el.dataset.cap;
|
|
}
|
|
});
|
|
});
|
|
|
|
form.addEventListener("submit", async (event) => {
|
|
event.preventDefault();
|
|
const button = form.querySelector('button[type="submit"]');
|
|
const data = new FormData(form);
|
|
const payload = {};
|
|
data.forEach((v, k) => { payload[k] = v; });
|
|
if (payload.website) return; // honeypot: pretend success, send nothing
|
|
if (capField && !payload.capabilities) payload.capabilities = capField.value;
|
|
button.disabled = true;
|
|
button.textContent = STRINGS.sending || "Sending…";
|
|
try {
|
|
const res = await fetch(form.dataset.webhook, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(payload),
|
|
});
|
|
if (!res.ok) throw new Error("HTTP " + res.status);
|
|
form.innerHTML =
|
|
'<p class="lead-ok"></p>';
|
|
form.querySelector(".lead-ok").textContent = form.dataset.i18nSuccess;
|
|
} catch {
|
|
const p = document.createElement("p");
|
|
p.className = "lead-err";
|
|
p.textContent = form.dataset.i18nError + " ";
|
|
const a = document.createElement("a");
|
|
a.href = `mailto:${form.dataset.contactEmail}?subject=Validation%20Lab`;
|
|
a.textContent = form.dataset.contactEmail;
|
|
p.appendChild(a);
|
|
form.innerHTML = "";
|
|
form.appendChild(p);
|
|
button.disabled = false;
|
|
}
|
|
});
|
|
})();
|
|
</script>
|
|
</section>
|