- All Courses
- Next.js for Production
- Server Actions and Mutations
- Form validation and progressive enhancement
Form validation and progressive enhancement
Client-side validation is a convenience for the user.
Overview
Validate where it counts, enhance where it helps
Client-side validation is a convenience for the user. Server-side validation is the one that protects your data, because the client one can simply be skipped. Parse the submitted form data against a schema at the top of the action and return structured errors when it fails.
Because a form wired to a Server Action submits as an ordinary HTML form, it works before the page has hydrated. That is real progressive enhancement rather than a slogan: a slow connection degrades to a full page submit instead of a dead button.
Pending state comes from the framework hooks rather than from your own state variable, which keeps it correct when a submission is interrupted or replayed.
In this lesson you will:
- Validate on the server and return field errors
- Keep the form working before JavaScript loads
- Show pending state during submission
Resources
Notes are not saved yet — they clear when you leave this page.
Writing your first Server Action
7m
Optimistic updates with useOptimistic
9m