Instructions
When to Use
- Use for accessible forms with zod + Server Actions or client submit.
- Prefer
api-handbookfor pure JSON APIs without forms. - Prefer
accessibility-auditfor a full WCAG pass after the form ships.
Build or audit forms with zod and accessible markup.
Decision: Server Action vs client submit vs API
| Situation | Prefer |
|---|---|
| Same-origin App Router mutation | Server Action + useActionState |
| SPA talking to JSON API | Client form → api-handbook Route Handler |
| Progressive enhancement required | Server Action with native form action |
| Multi-step wizard with heavy client UX | Controlled client + shared zod schema |
- Choose pattern: Server Action with
useActionState(React 19) or legacyuseFormStatenaming in older docs - match repo and installedreacttypes. - Single zod schema (or layered: base + refine); map
flatten().fieldErrorsto fields by name. - Labels,
htmlFor,aria-invalid,aria-describedbyfor errors; no placeholder-only labels. - Disable double-submit; optimistic UI only when the user asks; show pending state.
- File uploads: size limits and
acceptlist in UI copy; validate again on the server. - Auth: Server Actions that mutate must re-check session/RBAC (
auth-handbook); never trust hidden role fields. - CSRF / cookies: same-site cookies + Server Actions are the default story; document exceptions.
Outcomes
- Schema snippet + error wiring plan + a11y checklist + pattern choice.
Output Rules
Show field error mapping table (field → zod path). Prefer small diffs.
Scope and boundaries
- In scope: one multi-field form or wizard step.
- Out of scope: payment PCI scope (
payments-handbook), captcha vendor selection unless the user names one.
Safety
- repo-files: edit form components only; no
.envvalues.
Troubleshooting
- Next 15 form types: align with current
reacttypes from the lockfile. - Hydration on date pickers: prefer server default string + client parse in an island.
- Empty fieldErrors: ensure zod path names match
name=attributes. - Action succeeds but UI stale: add
revalidatePath/ tags (server-caching-handbook).
Related skills
api-handbook- Route Handler APIs behind formsclient-data-fetching- client mutation patternsaccessibility-audit- accessible error messagingauth-handbook- authorize mutations
GitHub: https://github.com/bh611627/skillcodex/tree/main/skills/forms-and-validation/SKILL.md
npm: https://www.npmjs.com/package/@skillcodex/skills