Contact forms / Next.js
Contact form for Next.js without an API route
One client component that posts with fetch. No server action, no API route, no email SDK.
Why Next.js needs a form backend
The usual Next.js contact form is a server action or a route handler that calls an email API. That means an email provider account, API keys in environment variables, your own validation and your own spam checks, and a server runtime for a page that could be static.
With Wrenform, the browser posts straight to your endpoint. There is no key to hide: the form ID is public by design, and allowed origins stop other sites from using it. The page can stay static, and it works with output: "export".
The snippet
Replace YOUR_FORM_ID with the ID of your form.
// app/contact/contact-form.tsx — no server action or API route needed
"use client";
import { useState } from "react";
export function ContactForm() {
const [status, setStatus] = useState<"idle" | "sending" | "sent" | "error">("idle");
async function onSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
const form = e.currentTarget;
setStatus("sending");
const res = await fetch("https://wrenform.com/f/YOUR_FORM_ID", {
method: "POST",
headers: { Accept: "application/json" },
body: new FormData(form),
});
setStatus(res.ok ? "sent" : "error");
if (res.ok) form.reset();
}
return (
<form onSubmit={onSubmit}>
<input type="text" name="name" required />
<input type="email" name="email" required />
<textarea name="message" required />
<input type="text" name="_honey" style={{ display: "none" }} tabIndex={-1} autoComplete="off" />
<button type="submit" disabled={status === "sending"}>Send</button>
{status === "sent" && <p>Thanks, your message was sent.</p>}
{status === "error" && <p>Something went wrong. Please try again.</p>}
</form>
);
}Steps
- Create a form (free) and copy its form ID.
- Save the component as
app/contact/contact-form.tsxand replaceYOUR_FORM_ID. - Render
<ContactForm />from a page. The page can stay a server component. - Deploy, and add your domain to Allowed origins.
Spam handling
Spam filtering is on for every form, with no CAPTCHA: a hidden honeypot field, a timing check, rate limits per visitor, and a content score for links, keywords and gibberish. Spam goes to a separate tab and is never emailed. See how spam filtering works.
Every rejection comes back as JSON with a stable code, so the component can show a precise message, for example when a visitor hits the rate limit.
Deployment notes
- Netlify. Deploy as usual. Netlify only processes forms that carry its own
netlifyordata-netlifyattribute, so it leaves this form alone and the browser posts it to Wrenform. Add yournetlify.appaddress and your custom domain to Allowed origins. - Vercel. Nothing to configure. The Next.js build stays static; you don't need a serverless function for the form. Add your production domain to Allowed origins. Preview deployments get their own addresses, so leave the list empty while you test them, or add each one.
- Cloudflare Pages. No Pages Function needed. Add your
pages.devaddress and your custom domain to Allowed origins. If you set a Content-Security-Policy header, addform-action https://wrenform.com. - GitHub Pages. GitHub Pages serves static files only, which is all this form needs. Add
https://<user>.github.io(or your custom domain) to Allowed origins. The origin is the host only, without the repository path.
FAQ
Do I need a server action or an API route?
Does it work with static export?
Can I use it without JavaScript?
Where do I put the form ID?
Can my server receive submissions too?
Next steps
- The full Next.js guide: every option, testing, and common problems.
- Contact form for Astro without a backend
- HTML contact form without a backend
- Pricing: free for 250 submissions a month.