Next.js guide
Next.js contact form, without an API route
You could write a route handler, pick an email provider and handle spam yourself. Or post the form straight to Formcrate from a client component. It works the same on Vercel, Netlify or output: "export" static builds.
1Create a form and copy its key
Sign up with Google, create a form and enter the email address that should receive submissions. Copy the form key from the dashboard: it replaces
YOUR_FORM_KEYbelow. The free plan includes 500 submissions a month.2Add your form key to the environment
The form key is safe to expose in the browser: it can only create submissions. Lock it to your domain in the form settings to stop other sites from using it.
.env.localNEXT_PUBLIC_FORMCRATE_KEY=YOUR_FORM_KEY
3Create the form component
Sending
Accept: application/jsonmakes Formcrate answer with JSON instead of redirecting, so you can show your own success message without leaving the page.app/components/ContactForm.tsx'use client'; import { useState, type FormEvent } from 'react'; const ENDPOINT = `https://www.formcrate.dev/api/submit/${process.env.NEXT_PUBLIC_FORMCRATE_KEY}`; export default function ContactForm() { const [status, setStatus] = useState<'idle' | 'sending' | 'sent' | 'error'>('idle'); async function onSubmit(e: FormEvent<HTMLFormElement>) { e.preventDefault(); setStatus('sending'); const res = await fetch(ENDPOINT, { method: 'POST', headers: { Accept: 'application/json' }, body: new FormData(e.currentTarget), }); setStatus(res.ok ? 'sent' : 'error'); } if (status === 'sent') return <p>Thanks! We'll be in touch.</p>; return ( <form onSubmit={onSubmit}> <input type="text" name="name" placeholder="Name" required /> <input type="email" name="email" placeholder="Email" required /> <textarea name="message" placeholder="Message" required /> <input type="text" name="_gotcha" style={{ display: 'none' }} tabIndex={-1} autoComplete="off" /> <button type="submit" disabled={status === 'sending'}> {status === 'sending' ? 'Sending…' : 'Send'} </button> {status === 'error' && <p>Something went wrong. Please try again.</p>} </form> ); }4Use it on any page
Pages can stay server components: only the form itself runs in the browser.
app/contact/page.tsximport ContactForm from '../components/ContactForm'; export default function ContactPage() { return ( <main> <h1>Contact us</h1> <ContactForm /> </main> ); }5Send a test submission
Fill in the form on your site and submit it. The message appears in your Formcrate inbox and arrives by email within a few seconds. Anything that looks like spam goes to the Spam tab instead and isn't emailed.
6Lock the form to your domain
Your key is visible in the page source, which is normal for form backends. In the form settings, add your domain under Domain lock so other websites can't post to your form from the browser.
Tips
- Using the Pages Router? The same component works: drop the
'use client'line. - Restart
next devafter editing.env.localso the new variable is picked up.
Get your Next.js form working
Free for 500 submissions a month. Spam filtering, email alerts and an inbox included. No card required.