Guide · 2 minutes
Contact form for Next.js
No API route, no server action, no email service. Post the form to betterform and every answer lands in Slack, Discord or email.
Create a form and copy its URL
Sign in, create a form, and copy the submit URL from its setup page. That URL is the whole backend.
Post the form to it
Send FormData with an Accept header and you get JSON back, so the visitor stays on the page.
'use client'
export function ContactForm() {
async function send(data: FormData) {
const res = await fetch('https://betterform.dev/f/k7m2x9', {
method: 'POST',
headers: { Accept: 'application/json' },
body: data,
})
const { ok } = await res.json()
alert(ok ? 'Thanks, we got it.' : 'Something went wrong.')
}
return (
<form action={send}>
<input name="email" type="email" required />
<textarea name="message" />
<button>Send</button>
</form>
)
}Pick where answers go
Add a Slack channel, a Discord channel or an email address. Every submission goes there, and spam is held back without captchas.
Rather not write it? Ask your agent.
Add a contact form to my Next.js app with betterform.