Skip to content
FormToMail

Static sites & frameworks

How do I handle forms in a Next.js static export (output: 'export')?

By the FormToMail team · Checked against official sources · Updated

With output: 'export', Next.js lists Server Actions and Route Handlers that rely on the Request as unsupported, because there is no Node.js server. Forms in a static export must be submitted from a client component (or a plain HTML `action`) to an external form endpoint or API.

Next.js form options by deployment
DeploymentServer ActionsRoute Handlers (POST)External form endpoint
output: 'export' (static)Not supportedNot supported (only static GET)Yes
Node server / VercelYesYesYes

Client component for a static export

tsx
"use client";
import { useState } from "react";

export default function Contact() {
  const [sent, setSent] = useState(false);
  return sent ? <p>Thanks! We'll reply soon.</p> : (
    <form
      onSubmit={async (e) => {
        e.preventDefault();
        const res = await fetch("https://getformtomail.com/f/YOUR_FORM_ID", {
          method: "POST",
          body: new FormData(e.currentTarget),
          headers: { Accept: "application/json" },
        });
        if (res.ok) setSent(true);
      }}
    >
      <input name="email" type="email" required />
      <textarea name="message" required />
      <button>Send</button>
    </form>
  );
}

Or no JavaScript at all

A plain <form action="…" method="POST"> also works in a static export: the browser posts straight to the endpoint and is redirected to a thank-you page.

Quick answers

Best way to handle forms in a next.js static export?

Post from a client component (or plain HTML) to an external form endpoint; Server Actions don't exist without a server.

Can I use Server Actions on Vercel instead?

Yes, if you drop output: 'export' and deploy with a server runtime.

How do I add a form to a vercel-hosted static site?

Same as any static site: a form endpoint in the action, or a Vercel Function you write.

What to do next

Create an endpoint and use it in the client component above.

Get your form endpoint

Sources

Checked: . Prices, limits and features of other services change: confirm current values at the official links above. Product names belong to their owners; we are not affiliated with them.