Connect your form
Choose your framework and site protection, then replace the placeholders. Your form’s Connect your website panel supplies code with the exact values.
This version needs no Turnstile. Keep _intent_id and the saved: true check: reuse the intent for a retry, and replace it only after a confirmed save or an explicit new message.
<form data-fi-form action="https://formpostbox.com/f/YOUR_FORM_ID" method="post">
<label>
Email
<input type="email" name="email" autocomplete="email" maxlength="254" required />
</label>
<label>
Message
<textarea name="message" maxlength="5000" required></textarea>
</label>
<input type="hidden" name="_intent_id" value="" />
<button type="submit">Send message</button>
<button type="reset">New message</button>
</form>
<script>
(() => {
const form = document.currentScript?.previousElementSibling;
if (!(form instanceof HTMLFormElement)) return;
const intent = form.elements.namedItem("_intent_id");
if (!(intent instanceof HTMLInputElement)) return;
let sending = false;
const status = document.createElement("p");
status.setAttribute("role", "status");
form.append(status);
const clearFields = () => {
form.querySelectorAll("input:not([type=hidden]), textarea, select").forEach((field) => {
if (field instanceof HTMLInputElement && ["button", "submit", "reset", "image"].includes(field.type)) return;
if (field instanceof HTMLInputElement && (field.type === "checkbox" || field.type === "radio")) field.checked = false;
else if (field instanceof HTMLSelectElement) field.selectedIndex = -1;
else if (field instanceof HTMLInputElement || field instanceof HTMLTextAreaElement) field.value = "";
});
};
const startNewMessage = () => {
intent.value = crypto.randomUUID();
};
form.addEventListener("reset", (event) => {
// Prevent the native reset from clearing the newly generated intent.
event.preventDefault();
if (sending) return;
clearFields();
startNewMessage();
status.textContent = "";
});
form.addEventListener("submit", async (event) => {
event.preventDefault();
if (sending) return;
// A network retry reuses this intent; only a new message rotates it.
sending = true;
form.querySelectorAll("button").forEach((button) => { button.disabled = true; });
status.textContent = "Sending…";
try {
const payload = Object.fromEntries(new FormData(form).entries());
const result = await fetch(form.action, {method: "POST", body: JSON.stringify(payload), headers: {"Content-Type": "application/json", Accept: "application/json"}});
const body = await result.json().catch(() => null);
if (result.status === 409 && body?.error === "conflict") {
status.textContent = "This message conflicts with an earlier submission. Restore the original content to retry, or choose New message to start again.";
return;
}
if (body?.saved === false) {
status.textContent = "Message was not saved. Try again.";
return;
}
if (!result.ok || !body?.saved) {
status.textContent = "Could not confirm saving. Retry the same message.";
return;
}
status.textContent = "Message saved.";
clearFields();
startNewMessage();
} catch {
status.textContent = "Could not confirm saving. Retry the same message.";
} finally {
sending = false;
form.querySelectorAll("button").forEach((button) => { button.disabled = false; });
}
});
startNewMessage();
})();
</script>Choose the protection setting that matches your site. Without protection, replace only YOUR_FORM_ID. With protection on, also replace YOUR_TURNSTILE_SITE_KEY and configure its matching widget. These placeholders make the examples reference material, not runnable code as written.
For your exact current configuration, open the form in your workspace and choose Connect your website. Both versions include _intent_id and confirm saved: true; only the protected version includes a widget, Turnstile script and cf-turnstile-response.
Configure your allowed origin, then copy from your form’s page. Turnstile is optional; when enabled, never include its secret in frontend code — only the public Site Key belongs there. Set up Turnstile →
Replace the values for your configuration
YOUR_FORM_ID— your form’s own id, shown on your form’s page and inside the generated code. It looks like7f3c5b12-6db4-4f9a-91cb-7f5c5b7f8a31. Replace only this part and keephttps://formpostbox.com/f/exactly as shown: that is FormPostbox’s submission address, not your website’s address.YOUR_TURNSTILE_SITE_KEY— required only with protection on: the public Site Key of your Turnstile widget, the same value you saved under Sites → Spam protection. It starts with0x. Never paste the Secret Key here.
Three addresses, three different jobs
- Submission address —
https://formpostbox.com/f/YOUR_FORM_ID. Goes into the form’saction. It always stays on formpostbox.com; only the form id changes. - Allowed origin —
https://www.example.com. Saved in your site’s FormPostbox settings. The exact origin where your form runs: scheme, hostname, and port, with no path. - Widget hostname —
www.example.com. Saved in your Cloudflare Turnstile widget. Hostname only, with no scheme, port, or path.
The allowed origin must always match your website. If you enable protection, the widget hostname must also match; the Turnstile setup guide walks through both settings side by side.
Putting the code on your website
Where the code goes: place HTML at the form location and keep its script immediately after it. The React example is a .tsx component: import it and render <ContactForm /> in your page; keep 'use client' in Next.js. For a plain JavaScript React project, remove TypeScript annotations. Put the Astro example in ContactForm.astro and import it into a page. Turnstile is needed only for the protected version.
- HTML — paste the form markup where the form should appear, and keep the script right after it: the script finds the form above it. Every field carries a
nameattribute, and named fields are what gets stored. - React — keep the
'use client'directive: this component runs in the browser; the protected version mounts Turnstile itself. Import it into your page and render it where the form should appear. - Astro — keep the frontmatter constants and the
is:inlinescript: Astro ships the markup as-is, and the script runs the same form lifecycle in the browser.
Working notes for all three: only protected sites need a Turnstile token, produced by the widget rather than hardcoded. Unprotected sites need no widget or token; the _intent_id is created when the form loads, and a network retry reuses it; and New message starts fresh — empty fields, a new intent, and a fresh challenge only when protection is on. In plain words: if sending fails, press Send message again to retry the same message without storing it twice; once it is saved the form clears and prepares a new message automatically. You can fill it in again immediately. Use New message when you want to clear the current fields and start over.
Check your first submission
Send a test from your allowed website, then open Inbox. Confirm that the message is saved and inspect its separate notification status.
Still need help? Contact support@formpostbox.com. Include the guide topic and redacted error details, without keys or visitor messages.
Browse all topics ↑