Form basics
Form validation
Form validation is checking that the data a visitor submits is complete and in the right format, before it is accepted, stored or acted on.
Also called: client-side validation, server-side validation, input validation
Validation answers two questions about a submission: is everything there, and is it in the shape we expect? An email field should hold an email address, a quantity should be a number and a file should be of an allowed type and size.
Client-side validation
The browser checks the form before it sends anything, using attributes such as required, type="email", min, max and pattern, or JavaScript. It gives the visitor instant feedback and saves a round trip. It is a convenience, not a safeguard: anyone can turn off JavaScript, edit the page or post to the endpoint directly.
Server-side validation
The server checks every submission again, whatever the browser did. This is the check that counts. It decides what is stored and what is acted on, and it is where limits on length, number format, file type and size belong.
A good server-side response says exactly what was wrong, per field, so the page can show the message next to the right input.
What good validation avoids
- Rejecting valid input, for example by refusing a
+in an email address or a name with an apostrophe. - Accepting everything and cleaning up later.
- Messages like “Invalid input” that do not say which field or why.
In StaticForm
Fields have a type (text, number, boolean, enum, date, datetime or file) and optional rules such as Email, Website, number ranges, date ranges, file extension and file size. Every value except a file upload is limited to 5,000 characters. These checks run on the server for every submission. When one fails, the API answers 400 Bad Request with a list of errors, one entry per failing field, and the JavaScript helper maps each entry onto the matching input.
Learn more
Related terms
- Multipart form datamultipart/form-data is a way to encode a form submission as separate parts, one per field. HTML forms need it whenever they include a file upload.
- Form submissionA form submission is one completed send of a form: the values the visitor entered, plus details such as the time, that a backend receives, checks and stores.
- Honeypot fieldA honeypot field is a form input hidden from people but visible to bots. Real visitors leave it empty, so any value in it marks the submission as spam.