How to add a form to Next.js
A Next.js contact form does not need a route handler or a server action. Post straight to FormTango from a client component.
- 1
Create a free FormTango account and add a form. Copy its endpoint, which looks like https://formtango.com/f/YOUR_FORM_ID.
- 2
Add this client component and use it on any page.
- 3
Submit the form once. The submission appears in your FormTango inbox and you get an email.
tsx
'use client';
import { useState } from 'react';
const ENDPOINT = 'https://formtango.com/f/YOUR_FORM_ID';
export default function ContactForm() {
const [status, setStatus] = useState('idle');
async function send(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
setStatus('sending');
const response = await fetch(ENDPOINT, {
method: 'POST',
headers: { Accept: 'application/json' },
body: new FormData(event.currentTarget),
});
setStatus(response.ok ? 'sent' : 'error');
}
if (status === 'sent') return <p>Thanks! We got your message.</p>;
return (
<form onSubmit={send}>
<input type="email" name="email" required />
<textarea name="message" required />
<input type="text" name="_gotcha" style={{ display: 'none' }} tabIndex={-1} autoComplete="off" />
<button disabled={status === 'sending'}>Send</button>
{status === 'error' && <p role="alert">Something went wrong. Please try again.</p>}
</form>
);
}Good to know
- This works with static export (output: "export") too, because nothing runs on your server.
What you get
- Every submission saved in an inbox you can search and export.
- An email for each one, with the visitor's address as the reply-to.
- Spam filtering without making visitors solve a puzzle.
- Problems? See troubleshooting.
Related guides
Last reviewed November 19, 2026.