JavaScript (fetch)
Keep your own HTML form and submit it without a page reload.
contact.js
const form = document.querySelector("#contact-form");
form.addEventListener("submit", async (event) => {
event.preventDefault();
const res = await fetch("https://api.formtura.app/v1/submit/YOUR_FORM_ID", {
method: "POST",
headers: { "Content-Type": "application/json", Accept: "application/json" },
body: JSON.stringify(Object.fromEntries(new FormData(form))),
});
const data = await res.json().catch(() => ({}));
if (res.ok) {
form.reset();
alert(data.message); // or follow data.redirect if you set a redirect URL
} else {
alert(data.error ?? "Something went wrong.");
}
});The response
200 OK
{ "success": true, "ok": true, "message": "Thanks! Your message has been sent." }403 Forbidden
{ "success": false, "ok": false, "code": "origin_not_allowed",
"error": "This website isn't allowed to submit to this form." }Check res.ok (or data.success). If you set a redirect URL on the form, a successful JSON response includes it as data.redirect.
CORS
The endpoint answers browser preflight requests for the domains you allowed. You don't need a proxy. If you see a CORS error, check that your site's domain is in the form's allowed domains.