Move the contact form from FormSubmit to Web3Forms
The form now posts with fetch. On success it goes to the thanks page; if the provider fails or is down, it shows an inline message with a mailto link prefilled with what the visitor wrote, instead of leaving them on the provider's error page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,14 +33,14 @@ The name carries this: **2π is a full turn, 360°**, meaning complete, end-to-e
|
|||||||
## Operating Context
|
## Operating Context
|
||||||
|
|
||||||
- Buyers evaluate the studio from the landing page, often comparing several vendors, before reaching out.
|
- Buyers evaluate the studio from the landing page, often comparing several vendors, before reaching out.
|
||||||
- The conversion path is a contact form (name, company, email, message) sent through FormSubmit, which redirects to `/gracias`.
|
- The conversion path is a contact form (name, company, email, message) sent through Web3Forms (posted with fetch; on success the page goes to `/gracias`, on failure it offers a prefilled email link).
|
||||||
- Analytics: PostHog (key via `POSTHOG_API_KEY`) and an OpenReplay session-recording snippet are currently on the page.
|
- Analytics: PostHog (key via `POSTHOG_API_KEY`) and an OpenReplay session-recording snippet are currently on the page.
|
||||||
|
|
||||||
## Capabilities and Constraints
|
## Capabilities and Constraints
|
||||||
|
|
||||||
- Services offered (from the current site): custom software, process automation, systems integration, web and mobile apps (iOS/Android), cloud architecture.
|
- Services offered (from the current site): custom software, process automation, systems integration, web and mobile apps (iOS/Android), cloud architecture.
|
||||||
- Working stack: .NET, TypeScript, React, PostgreSQL, AWS.
|
- Working stack: .NET, TypeScript, React, PostgreSQL, AWS.
|
||||||
- Site stack: static Eleventy + Tailwind CSS, built with Bun, served by Nginx through Docker on Dokploy. There is no backend; the form posts to FormSubmit.
|
- Site stack: static Eleventy + Tailwind CSS, built with Bun, served by Nginx through Docker on Dokploy. There is no backend; the form posts to Web3Forms.
|
||||||
- Languages: Spanish (neutral Latin American, **tú**) is primary; English is built alongside it for English-speaking clients.
|
- Languages: Spanish (neutral Latin American, **tú**) is primary; English is built alongside it for English-speaking clients.
|
||||||
- Response time: every inquiry gets a reply within **1 business day** (confirmed). A written proposal is delivered before the client commits (confirmed).
|
- Response time: every inquiry gets a reply within **1 business day** (confirmed). A written proposal is delivered before the client commits (confirmed).
|
||||||
- **Undecided:** where the studio is based and whether to say so publicly; pricing or engagement model; whether to keep OpenReplay session recording.
|
- **Undecided:** where the studio is based and whether to say so publicly; pricing or engagement model; whether to keep OpenReplay session recording.
|
||||||
|
|||||||
@@ -157,13 +157,15 @@ module.exports = {
|
|||||||
submit: "Enviar mensaje",
|
submit: "Enviar mensaje",
|
||||||
sending: "Enviando…",
|
sending: "Enviando…",
|
||||||
privacy:
|
privacy:
|
||||||
"El formulario se envía a través de FormSubmit solo para responderte. Usamos analítica (PostHog y OpenReplay) para mejorar el sitio; lo que escribes en el formulario no se registra en esas herramientas.",
|
"El formulario se envía a través de Web3Forms solo para responderte. Usamos analítica (PostHog y OpenReplay) para mejorar el sitio; lo que escribes en el formulario no se registra en esas herramientas.",
|
||||||
subject: "Nueva consulta desde 2pidev.com",
|
subject: "Nueva consulta desde 2pidev.com",
|
||||||
errors: {
|
errors: {
|
||||||
name: "Escribe tu nombre para saber a quién responder.",
|
name: "Escribe tu nombre para saber a quién responder.",
|
||||||
email: "Revisa el email: debe tener el formato nombre@empresa.com.",
|
email: "Revisa el email: debe tener el formato nombre@empresa.com.",
|
||||||
message: "Cuéntanos en unas líneas qué necesitas resolver.",
|
message: "Cuéntanos en unas líneas qué necesitas resolver.",
|
||||||
summary: "Revisa los campos marcados para poder enviar el mensaje.",
|
summary: "Revisa los campos marcados para poder enviar el mensaje.",
|
||||||
|
send: "No pudimos enviar tu mensaje. Inténtalo de nuevo en un momento o escríbenos a",
|
||||||
|
sendMail: "el correo se abre con lo que ya escribiste.",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -340,13 +342,15 @@ module.exports = {
|
|||||||
submit: "Send message",
|
submit: "Send message",
|
||||||
sending: "Sending…",
|
sending: "Sending…",
|
||||||
privacy:
|
privacy:
|
||||||
"The form is sent through FormSubmit only so we can reply to you. We use analytics (PostHog and OpenReplay) to improve the site; what you type in the form is not recorded in those tools.",
|
"The form is sent through Web3Forms only so we can reply to you. We use analytics (PostHog and OpenReplay) to improve the site; what you type in the form is not recorded in those tools.",
|
||||||
subject: "New inquiry from 2pidev.com (EN)",
|
subject: "New inquiry from 2pidev.com (EN)",
|
||||||
errors: {
|
errors: {
|
||||||
name: "Add your name so we know who to reply to.",
|
name: "Add your name so we know who to reply to.",
|
||||||
email: "Check the email: it should look like name@company.com.",
|
email: "Check the email: it should look like name@company.com.",
|
||||||
message: "Tell us in a few lines what you need to solve.",
|
message: "Tell us in a few lines what you need to solve.",
|
||||||
summary: "Check the highlighted fields to send your message.",
|
summary: "Check the highlighted fields to send your message.",
|
||||||
|
send: "We couldn't send your message. Try again in a moment, or email us at",
|
||||||
|
sendMail: "the email opens with what you already wrote.",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
url: 'https://www.2pidev.com',
|
url: 'https://www.2pidev.com',
|
||||||
email: 'hola@2pidev.com',
|
email: 'hola@2pidev.com',
|
||||||
|
// Web3Forms public access key (meant to live in the page; it only lets the form deliver to our inbox)
|
||||||
|
web3formsKey: 'd6d650a2-aca0-45fd-abf2-2c9729444640',
|
||||||
year: new Date().getFullYear(),
|
year: new Date().getFullYear(),
|
||||||
posthogKey: process.env.POSTHOG_API_KEY || null,
|
posthogKey: process.env.POSTHOG_API_KEY || null,
|
||||||
posthogHost: process.env.POSTHOG_API_HOST || 'https://us.i.posthog.com',
|
posthogHost: process.env.POSTHOG_API_HOST || 'https://us.i.posthog.com',
|
||||||
|
|||||||
@@ -221,16 +221,18 @@
|
|||||||
<p class="mt-8 text-night-muted">{{ t.contact.orEmail }} <a class="night-link" href="mailto:{{ site.email }}">{{ site.email }}</a></p>
|
<p class="mt-8 text-night-muted">{{ t.contact.orEmail }} <a class="night-link" href="mailto:{{ site.email }}">{{ site.email }}</a></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form class="lg:col-span-7" action="https://formsubmit.co/{{ site.email }}" method="POST" data-contact-form
|
<form class="lg:col-span-7" action="https://api.web3forms.com/submit" method="POST" data-contact-form
|
||||||
data-sending="{{ fm.sending }}"
|
data-sending="{{ fm.sending }}" data-thanks="{{ t.thanksUrl }}" data-email="{{ site.email }}"
|
||||||
|
data-err-send="{{ fm.errors.send }}" data-err-send-mail="{{ fm.errors.sendMail }}"
|
||||||
data-err-name="{{ fm.errors.name }}" data-err-email="{{ fm.errors.email }}"
|
data-err-name="{{ fm.errors.name }}" data-err-email="{{ fm.errors.email }}"
|
||||||
data-err-message="{{ fm.errors.message }}" data-err-summary="{{ fm.errors.summary }}">
|
data-err-message="{{ fm.errors.message }}" data-err-summary="{{ fm.errors.summary }}">
|
||||||
<input type="hidden" name="_next" value="{{ t.thanksUrl }}">
|
<input type="hidden" name="access_key" value="{{ site.web3formsKey }}">
|
||||||
<input type="hidden" name="_subject" value="{{ fm.subject }}">
|
<input type="hidden" name="subject" value="{{ fm.subject }}">
|
||||||
<input type="hidden" name="_template" value="table">
|
<input type="hidden" name="from_name" value="2pidev.com">
|
||||||
|
<input type="hidden" name="redirect" value="{{ t.thanksUrl }}">
|
||||||
<input type="hidden" name="idioma" value="{{ t.htmlLang }}">
|
<input type="hidden" name="idioma" value="{{ t.htmlLang }}">
|
||||||
<div class="absolute -left-[9999px] h-px w-px overflow-hidden" aria-hidden="true">
|
<div class="absolute -left-[9999px] h-px w-px overflow-hidden" aria-hidden="true">
|
||||||
<label>Leave empty <input type="text" name="_honey" tabindex="-1" autocomplete="off"></label>
|
<label>Leave empty <input type="checkbox" name="botcheck" tabindex="-1" autocomplete="off"></label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-summary mb-6" role="alert" tabindex="-1" data-form-summary hidden></div>
|
<div class="form-summary mb-6" role="alert" tabindex="-1" data-form-summary hidden></div>
|
||||||
@@ -422,11 +424,39 @@
|
|||||||
firstBad.el.focus();
|
firstBad.el.focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Send in the background so a provider outage never leaves the visitor on an error page
|
||||||
|
e.preventDefault();
|
||||||
summary.hidden = true;
|
summary.hidden = true;
|
||||||
submit.setAttribute('aria-busy', 'true');
|
submit.setAttribute('aria-busy', 'true');
|
||||||
submitLabel.textContent = form.dataset.sending;
|
submitLabel.textContent = form.dataset.sending;
|
||||||
if (window.posthog) window.posthog.capture('contact_form_submitted', { lang: document.documentElement.lang });
|
var lang = document.documentElement.lang;
|
||||||
|
fetch(form.action, { method: 'POST', body: new FormData(form), headers: { Accept: 'application/json' } })
|
||||||
|
.then(function (r) { return r.json().then(function (d) { if (!r.ok || !d.success) throw new Error(d.message || r.status); }); })
|
||||||
|
.then(function () {
|
||||||
|
if (window.posthog) window.posthog.capture('contact_form_submitted', { lang: lang });
|
||||||
|
window.location.href = new URL(form.dataset.thanks).pathname;
|
||||||
|
})
|
||||||
|
.catch(function () {
|
||||||
|
if (window.posthog) window.posthog.capture('contact_form_failed', { lang: lang });
|
||||||
|
sendFailed();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fallback when sending fails: an email link that carries what the visitor already wrote
|
||||||
|
function sendFailed() {
|
||||||
|
submit.removeAttribute('aria-busy');
|
||||||
|
submitLabel.textContent = idleLabel;
|
||||||
|
var v = function (sel) { return form.querySelector(sel).value.trim(); };
|
||||||
|
var body = v('#f-message') + '\n\n— ' + v('#f-name') + (v('#f-company') ? ', ' + v('#f-company') : '') + '\n' + v('#f-email');
|
||||||
|
var link = document.createElement('a');
|
||||||
|
link.className = 'night-link';
|
||||||
|
link.href = 'mailto:' + form.dataset.email + '?subject=' + encodeURIComponent(form.querySelector('[name=subject]').value) + '&body=' + encodeURIComponent(body);
|
||||||
|
link.textContent = form.dataset.email;
|
||||||
|
summary.textContent = '';
|
||||||
|
summary.append(form.dataset.errSend + ' ', link, ': ' + form.dataset.errSendMail);
|
||||||
|
summary.hidden = false;
|
||||||
|
summary.focus();
|
||||||
|
}
|
||||||
|
|
||||||
// Restore the button if the visitor comes back with the browser's back button
|
// Restore the button if the visitor comes back with the browser's back button
|
||||||
var idleLabel = submitLabel.textContent;
|
var idleLabel = submitLabel.textContent;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user