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.

RuleWhat it checks
RequiredThe field must be present and non-empty.
TypeEmail, URL, number, or phone. Blank values pass unless the field is also required.
Min / max lengthCharacter-count bounds for text.
Min / max valueNumeric bounds (for a number type).
PatternA regular expression the value must match.
Custom messageOverrides the default error text for that field.
Optional fields stay optional: A rule with a type or length but not marked required only runs when the field has a value. Leave an optional field blank and it passes; fill it in and it must be valid.

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.

contact.js
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.

422 response
{
  "ok": false,
  "error": "validation",
  "message": "Some fields need attention.",
  "fields": {
    "email": "Enter a valid email address.",
    "message": "Must be at least 10 characters."
  }
}
Plain HTML forms (no JavaScript): A normal browser form post can't receive a JSON body, so an invalid submission is redirected to a hosted error page asking the visitor to go back and fix their entries. For inline, field-level errors, use the fetch() approach above or the JavaScript SDK.

Related