Menu

A spam-resistant contact form in the Next.js App Router (Server Actions, Zod, useActionState)
📰

A spam-resistant contact form in the Next.js App Router (Server Actions, Zod, useActionState)

DEV Community: nextjs·Sushil Barwal·about 7 hours ago
#op1sf9y2
#devtonextjs#devto#dev#server#form
Long article (1971 words) — no AI summary yet.
Reading 0:00
15s threshold

Almost every business website needs a contact form, and almost every contact form ends up as a target for bots. In the Next.js App Router you no longer need a separate API route for this: a Server Action can receive the form, validate it and send the enquiry, while the page keeps working even before JavaScript loads.

This tutorial builds that form step by step:

A plain form component

A Server Action that receives it

Validation with Zod

A honeypot field and a timing check for bots

Field errors and a pending state with useActionState

It assumes Next.js 15 or later (React 19) with the App Router and TypeScript. Install Zod with npm install zod .

1. The form component

Start with a normal HTML form.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.