--- name: netlify-forms description: Use this skill whenever a developer wants to add a contact form, signup form, file upload form, or any HTML form to a Netlify site without a backend, or asks why form submissions are missing, going to spam, or returning 404. It covers data-netlify form markup, AJAX/fetch submission, React/Vue/Next.js/Nuxt/SvelteKit/Astro JS-rendered or SSR forms that need a static skeleton, custom thank-you pages, honeypot or reCAPTCHA spam protection, email/Slack/webhook notifications and subject lines, reading or exporting submissions through the Netlify API, and triggering functions on form submission. --- # Netlify Forms ## Use this / not that ```html
…
``` ```js // ✅ URL-encoded body built from FormData fetch(target, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: new URLSearchParams(new FormData(form)).toString(), }); // ❌ JSON is NOT supported. Submissions are lost. fetch(target, { method: "POST", body: JSON.stringify(data) }); ``` - `netlify` (bare attribute) works the same as `data-netlify="true"`. - `data-remove-prefix` only applies to legacy forms created before May 5, 2023. Don't add it to new forms. > ⚠️ **Prerequisite:** enable **Forms > Enable form detection** in the UI (https://app.netlify.com/projects/{site_name}/forms), then **redeploy**. Without detection, new or changed forms accept no submissions. Enabling has no effect until the next deploy. ## How detection works - At deploy time, Netlify parses the **static HTML output** and finds `
` tags with `data-netlify="true"` or `netlify`. - It strips that attribute (and `netlify-honeypot`) and injects ``. - The form `name` is the form's identity in the UI. It must be unique per site. - Fields are identified by their `name` attributes. Multi-selects can use `name="role[]"`. - Forms rendered only by client-side JS or SSR are invisible to the build. They need a static HTML counterpart. ## Static HTML form (complete) ```html
``` - **`action`:** optional custom success page. It must start with `/` (site-root relative). Without it, visitors see a generic Netlify success page. - **`email` field:** sets `Reply-to` on notification emails. Otherwise replies go to `formresponses@netlify.com`. - **`subject` hidden input:** sets the notification subject (details below). ### AJAX for a static page ```js document.querySelector("form").addEventListener("submit", (event) => { event.preventDefault(); fetch("/", { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: new URLSearchParams(new FormData(event.target)).toString(), }) .then(() => alert("Thank you for your submission")) .catch((error) => alert(error)); }); ``` `form-name` must be in the body. `FormData` picks up the injected hidden input automatically. ## JS-rendered / SSR forms (React, Vue, Gatsby, Next.js, Nuxt, SvelteKit, Astro) Two parts are required: a detectable static skeleton, plus a component that sends `form-name`. **1. `public/__forms.html`** — a hidden static copy of every form. Each input `name` must exactly match what the component submits. ```html ``` If the form uses Netlify-provided reCAPTCHA, also include `
` in the skeleton. **2. Component** — includes the hidden `form-name` input (or put `form-name` in the POST body) and submits via AJAX. ```jsx export default function PizzaForm() { const [status, setStatus] = useState(null); const handleSubmit = async (event) => { event.preventDefault(); const body = new URLSearchParams(new FormData(event.target)).toString(); try { const res = await fetch("/__forms.html", { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body, }); setStatus(res.ok ? "ok" : "error"); } catch { setStatus("error"); } }; return (
{status === "ok" &&

Thanks!

}
); } ``` - **Next.js Runtime v5 (Next.js 13.5+):** form definitions must live in a dedicated static HTML file, and submission must be AJAX, not full-page navigation. See https://docs.netlify.com/build/frameworks/framework-setup-guides/nextjs/overview#v5-breaking-changes - **After AJAX success:** handle it in JS, for example `navigate("/thank-you/")` in Gatsby, or set state as above. ## File uploads ```html
``` ```js document.forms.fileForm.addEventListener("submit", (event) => { event.preventDefault(); fetch("/", { method: "POST", body: new FormData(event.target) }); // NO Content-Type header }); ``` > ⚠️ **Do not set `Content-Type` when uploading files.** Pass `FormData` directly and let the browser set the multipart boundary. - One file per ``. Use multiple fields for multiple files. - The request is capped at **8 MB** total. - Uploads time out after **30 s**. - For uploads containing PII, add extra security (the docs suggest Very Good Security: https://www.netlify.com/integrations/very-good-security/). - File links are available in the API, the UI, notification emails, and CSV exports. ## Spam protection Akismet filters every submission automatically. Flagged submissions go to **Spam submissions**, not the default list. > ⚠️ **Honeypot and reCAPTCHA failures are rejected outright.** They never appear in the spam list, so there is nothing to recover. **Honeypot:** ```html
…
``` - The field must be hidden via CSS or JS. - Any value in the field causes a quiet rejection. - AJAX bodies must include the honeypot field. `FormData` does this. **Netlify-provided reCAPTCHA 2:** - Add `data-netlify-recaptcha="true"` on `
`. - Add `
` where the widget should render. - Only **one per page** is allowed. Use custom reCAPTCHA for more. - On failure, the visitor is redirected back to the same page. **Custom reCAPTCHA 2:** 1. Add your own Google widget and script. 2. Add `data-netlify-recaptcha="true"` on ``. 3. Set these env vars: | Var | Value | Scopes | |---|---|---| | `SITE_RECAPTCHA_KEY` | site key | **Builds + Runtime** | | `SITE_RECAPTCHA_SECRET` | secret key | **Runtime** | The body must include a valid `g-recaptcha-response` (`FormData` includes it). **Test submissions "missing":** they are probably in Akismet spam. Avoid this with a real email (not `test@test.com`), real sentences in textareas, and spaced-out submissions from the same IP. ## Notifications Configure in **Forms > Submission notifications** (https://app.netlify.com/projects/{site_name}/forms?tab=notifications). - **Destinations:** email, webhook (HTTP POST), or Slack (via https://docs.netlify.com/extend/install-and-use/setup-guides/netlify-app-for-slack). - **Integrations:** Zapier and n8n. - **Firing:** only on **verified** submissions, either per form or for all forms. **Email recipients** must be active team members or confirmed outside addresses: - An outside address stays **pending confirmation**. Nothing is sent until the owner clicks **Confirm** in the single confirmation email. - Confirmation is rolling out gradually. If unavailable, saving a non-team address fails validation. Invite the person to the team first. **Subject line:** - Use a hidden ``. - Variables: `%{formName}`, `%{siteName}`, `%{submissionId}`. - **The HTML subject overrides the UI subject.** To use the UI subject, remove the HTML input. - Legacy forms created before May 5, 2023 get a `[Netlify]` prefix. Drop it either with `data-remove-prefix` on the `subject` input or by setting the subject in the UI. ## Submissions & API **API** (https://docs.netlify.com/api-and-cli-guides/api-guides/get-started-with-api#forms): - Supports listing verified and spam submissions, plus deleting submissions or forms. - Endpoint: `listFormSubmissions` (https://open-api.netlify.com/#tag/submission/operation/listFormSubmissions). - The API retains data from renamed or removed fields. The UI shows only fields from the latest deployed form version. **Function on submission:** a function can run when a submission is verified. See https://docs.netlify.com/build/functions/trigger-on-events **UI** (**Forms** tab, under **Active forms**): - **CSV export:** **Download as CSV** exports verified submissions. - **State changes:** **Mark as spam** / **Mark as verified**. - **Deletion:** deleting submissions is permanent. **Submission summary** (shown for each item in the UI list): - Title: the first visible, non-email text ``. If none exists, a field named `title` or `subject` is used. - Body: the first `