JavaScript
Stay on the page after submit. PostMe returns JSON for cross-origin fetch and when the request asks for JSON.
FormData
Prevent the default submit, then POST the form as FormData. Field names are the same as in HTML forms, including hidden options.
submit.js
form.addEventListener("submit", async (event) => {
event.preventDefault();
const res = await fetch("https://api.postme.dev/submit/you@example.com", {
method: "POST",
body: new FormData(form),
});
const data = await res.json();
if (!data.ok) {
if (data.errorRedirect) location.href = data.errorRedirect;
else alert(data.message);
return;
}
if (data.status === "pending_confirmation") {
showBanner(data.message);
return;
}
if (data.redirect) location.href = data.redirect;
else showBanner(data.message);
});JSON body
You can also POST a flat JSON object. String, number, and boolean values become form fields. Nested objects are ignored.
fetch.json
await fetch("https://api.postme.dev/submit/you@example.com", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
name: "Ada",
email: "ada@example.com",
message: "Hello",
_subject: "New inquiry",
}),
});When you get JSON
A JSON body is returned when the request is cross-origin fetch, the Accept header includes application/json, or the form includes _postme_json.
Classic HTML submits use a navigation request. Those still redirect. Use fetch when you want to keep the visitor on your page. Agents and scripts should POST to an Intake URL — public
/submit requires Turnstile.