Skip to content
Wrenform

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

  1. Create a form (free) and copy its form ID.
  2. Save the component as app/contact/contact-form.tsx and replace YOUR_FORM_ID.
  3. Render <ContactForm /> from a page. The page can stay a server component.
  4. 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 netlify or data-netlify attribute, so it leaves this form alone and the browser posts it to Wrenform. Add your netlify.app address 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.dev address and your custom domain to Allowed origins. If you set a Content-Security-Policy header, add form-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?
No. The client component posts to Wrenform directly. You don't run any server code for the form.
Does it work with static export?
Yes. The form is client-side only, so output: export and hosts like GitHub Pages work.
Can I use it without JavaScript?
Yes. A plain form element with action and method POST works in a server component; the visitor comes back through a redirect.
Where do I put the form ID?
In the component, or in NEXT_PUBLIC_WRENFORM_ID. It is not a secret.
Can my server receive submissions too?
Yes, on Pro and Agency: add a webhook and verify its signature in a route handler.

Next steps