When a submission fails, you may want to show a dedicated error page instead of inline messaging. Formbase responds with standard HTTP status codes, so you can redirect based on the response.
Submit the form
Use fetch and inspect the response status.
Redirect on failure
const response = await fetch('https://formbase.dev/s/YOUR_FORM_ID', {
method: 'POST',
body: new FormData(formElement),
redirect: 'manual',
});
if (response.status === 303 || response.ok) {
window.location.href = '/thanks';
return;
}
window.location.href = `/error?reason=submit_failed&status=${response.status}`;
Include the status code or a reason string to help with debugging.
A 404 response usually means the form ID is invalid. A 500 response often indicates a server or storage configuration issue.