What is going on
Your form validation differs between client-side (JavaScript/React) and server-side (Next.js server action), allowing invalid data through or rejecting valid data. User experience is poor with inconsistent feedback.
Validation mismatch happens when client validation and server validation use different rules, or validation is skipped on one side.
Error messages you might see
Common causes
- Client uses custom validation rules, server uses different schema (Zod, Joi)
- Only client-side validation, no server-side validation of submitted data
- Server action accepts data without validation before database insert
- Different field requirements or constraints on client vs server
- No shared validation schema between front and backend
How to fix it
Use shared schema: Define validation with Zod schema used on both client and server:const schema = z.object({ email: z.string().email(), name: z.string().min(2) })
// In client component: schema.parse(data)
// In server action: schema.parse(formData)
Always validate server-side: Never trust client validation. Always validate in server action before database operation.
Return validation errors: Server action should return validation errors to display in form: return { errors: { email: 'Invalid email' } }
Use form libraries: React Hook Form + Zod handles both validation and error display.
Getting help takes about a minute
No hiring, no back and forth. A real person looks at your app.
-
1
Describe it
Tell us what you need in plain words. You don't have to be technical or have an account to start.
-
2
Free 15-minute call
A verified developer calls you. Many tasks are sorted right there, and it costs nothing.
-
3
Pay after you approve
If there is more to do, you get one fixed price up front. You pay only once you are happy.
Real people, reviewed by hand
Developers who do this every day
Every developer is approved by our team before they can take a task. Describe yours and the first one who is free picks it up.
Get helpQuestions
Should I validate on client, server, or both?
Both. Client validation for UX (fast feedback). Server validation for security (can't trust client). Use same schema for both.
What's the best validation library?
Zod for TypeScript-first schemas. Joi for pure JavaScript. Both work well with React Hook Form.
How do I display server validation errors?
Server action returns errors object. Client component stores in state and displays near form fields.