Guide
Validation
Server-side validation for your form fields: required, type, length, numeric range, and pattern. Submissions that fail are rejected before they are stored, and fetch() callers receive an HTTP 422 with a per-field error map.
HTML attributes like required and type="email" are enforced only in the browser, so a client that posts directly to your endpoint can skip them. ShipMyForm's rules run on the server for every submission, independent of the client. A submission that fails validation is rejected before it is stored, counted against your quota, or delivered to a connector.
Add rules in your dashboard
Open your form's Settings and find Validation rules. Add a rule per field you want to check. The field name must match your input's name attribute.
| Rule | What it checks |
|---|---|
| Required | The field must be present and non-empty. |
| Type | Email, URL, number, or phone. Blank values pass unless the field is also required. |
| Min / max length | Character-count bounds for text. |
| Min / max value | Numeric bounds (for a number type). |
| Pattern | A regular expression the value must match. |
| Custom message | Overrides the default error text for that field. |
Show errors inline with fetch()
Send Accept: application/json so ShipMyForm replies with JSON instead of redirecting. When a submission is invalid you get 422 with a fields map — field name to message — that you can render beside each input.
const form = document.querySelector("#contact");
form.addEventListener("submit", async (e) => {
e.preventDefault();
clearErrors(form);
const res = await fetch("https://shipmyform.com/f/frm_8Kx2mQ9pL4vN", {
method: "POST",
headers: { Accept: "application/json" },
body: new FormData(form),
});
const data = await res.json();
// Validation failed: show a message next to each field.
if (res.status === 422 && data.error === "validation") {
for (const [name, message] of Object.entries(data.fields)) {
showFieldError(form, name, message);
}
return;
}
if (data.ok) {
form.reset();
showSuccess();
}
});The 422 response
error is always "validation"; fields contains only the fields that failed.
{
"ok": false,
"error": "validation",
"message": "Some fields need attention.",
"fields": {
"email": "Enter a valid email address.",
"message": "Must be at least 10 characters."
}
}fetch() approach above or the JavaScript SDK.Related
- React & Next.js — the
fetch()pattern in a component. - Stop form spam without reCAPTCHA — the spam layer that runs alongside validation.