--- 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 ` ``` - **`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 ( ); } ``` - **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 `