Docs / Guides
Redirects and thank-you pages
After a visitor sends the form, they land on your page, ours, or stay where they are.
<input type="hidden" name="_redirect" value="https://example.com/thanks">Where the visitor lands
For a normal form post, we answer with a 303 redirect. We pick the first of these that applies:
- The
_redirectfield, if it's allowed (below). - Redirect to in the form's settings (the success URL).
- Our hosted thank-you page.
Spam gets the same redirect, so bots can't tell they were caught.
Your own thank-you page
The simplest way: set Redirect to in the form's settings, for example https://example.com/thanks. It must be an https:// address (http://localhost is allowed for testing). Nothing changes in your HTML.
The _redirect field
Use it when one form serves several pages, or each page needs its own thank-you page. We follow it only when:
- it's an absolute
http://orhttps://URL; and - its origin is in the form's Allowed origins, or, while that list is empty, it's the same origin as the page that posted.
Otherwise we ignore it and fall back to Redirect to, then our page. We are never an open redirect.
Our hosted thank-you page
It says "Thanks! Your message was sent." and has a Back link to the page the visitor came from. On the free plan it also shows a small "Form handled by Wrenform" link. It isn't indexed by search engines.
Errors have a hosted page too: it shows the HTTP status, a plain message and a Back link. Error codes are listed in errors.
Stay on the page
To show the result without leaving the page, send the form with JavaScript and ask for JSON. Redirect settings don't apply to JSON requests.
const form = document.querySelector("#contact");
form.addEventListener("submit", async (event) => {
event.preventDefault();
const res = await fetch(form.action, {
method: "POST",
headers: { Accept: "application/json" },
body: new FormData(form),
});
const result = await res.json();
if (result.ok) {
form.reset();
form.querySelector("[role=status]").textContent = "Thanks, your message was sent.";
} else {
form.querySelector("[role=status]").textContent = result.error.message;
}
});A request gets JSON when its body is application/json, or when its Accept header lists application/json before text/html. Success is { "ok": true, "id": "…" }. An error is { "ok": false, "error": { "code", "message", "docs" } } with the matching HTTP status.
Framework versions: Astro, Next.js.
Test it
Send the form and check the address bar: you should be on the page you chose. If you land on our thank-you page instead, your _redirect was ignored; see below.
Common problems
_redirectis ignored. Its origin isn't in Allowed origins. Add the origin (for examplehttps://example.com), or use Redirect to instead._redirectworks on the live site but not locally. Locally, the page's origin ishttp://localhost:…, which doesn't match the redirect's origin.- The browser blocks the redirect. A strict Content-Security-Policy
form-actionmust list your own origin as well as ours. See the HTML guide. - Relative URLs don't work. Use a full URL:
https://example.com/thanks, not/thanks.