Forms — Kendi Next.js
The forms of this Next.js template work as soon as you run it: the contact form and the newsletter sign-up.
The newsletter appears in three places: Home’s hero, the sidebar’s “Newsletter” card (Home and every post) and the “Stay updated with our letter” band above the footer (every page but the legal pages and the 404). The contact form is on Contact. Each form checks the required fields, shows a spinner while sending, says “Thank you” and clears the fields, keeps what the visitor typed when something fails (“Something went wrong”), and drops spam with a hidden honeypot field.
Out of the box, submissions are written to the server log (FORM_PROVIDER=console). That’s fine while you build, but
useless once you publish, so pick a destination before launch. One provider serves both forms; every submission carries
the name and title of its form, so you can tell them apart in your inbox or tool.
The quickest way to receive submissions
Section titled “The quickest way to receive submissions”-
Copy the example settings:
Terminal window cp .env.example .env.local -
Choose one:
You want Set Subscribers in a Mailchimp audience FORM_PROVIDER=mailchimp+MAILCHIMP_API_KEY,MAILCHIMP_AUDIENCE_ID; setMAILCHIMP_STATUStopendingorsubscribedto send them your newsletter (consent)An email for every submission FORM_PROVIDER=resend+RESEND_API_KEY,FORM_EMAIL_TO,FORM_EMAIL_FROMIt in another newsletter tool, a CRM, Slack, a spreadsheet… FORM_PROVIDER=webhook+FORM_WEBHOOK_URL(Zapier, Make, n8n, Formspree, your own API); optionalFORM_WEBHOOK_SECRETSeveral at once work:
FORM_PROVIDER=mailchimp,resendadds a subscriber to Mailchimp and emails you every contact message too. -
Restart
npm run devand send a test from each form. -
Put the same variables in your host’s dashboard before deploying.
.env.localis not uploaded.
Details for each provider, what it receives, the webhook payload, Mailchimp consent settings and how to write your own provider (Brevo, ConvertKit, Beehiiv…) are in Forms reference.
What the forms ask for
Section titled “What the forms ask for”The newsletter (form: newsletter, title “New newsletter subscriber”, button “Subscribe”):
| Field | Name it arrives under | Required |
|---|---|---|
email |
yes | |
| The consent box (the sidebar card and the band only) | consent (yes when ticked) |
The contact form on Contact (form: contact, title “New contact message”, button “Submit”):
| Field | Name it arrives under | Required |
|---|---|---|
| Name | Name |
yes |
Email |
yes | |
| Message | Message |
yes |
Resend puts the sender’s name after the title in the email’s subject and sets the reply address to the sender’s e-mail.
Mailchimp adds or updates the contact by e-mail, tags them with the title and keeps the rest as a note. A webhook
receives every field, as "" when left empty, with its label.
Changing the forms
Section titled “Changing the forms”The labels, placeholders, the button’s three texts and the title of each submission are content:
| Form | Copy | Server action |
|---|---|---|
| Newsletter | newsletter.form in src/content/site.ts (the band and the sidebar card), hero.subscribe in src/content/pages/home.ts (Home’s hero) |
subscribe in src/lib/actions.ts |
| Contact | form in src/content/pages/contact.ts |
submitContact in src/lib/actions.ts |
A field arrives at your provider under its name, so keep the names you already map somewhere. The contact form’s
server action sends every field listed in its copy and checks the required ones again on the server, so the list in
the copy is the place to edit:
-
To make a field optional, remove
"required": truefrom it. The browser checks required fields before sending and the server checks them again; the submit button stays faded until they are filled. -
To add a field, add an entry, for example a subject:
"subject": { "name": "Subject", "label": "Subject", "placeholder": "What is it about?" },The types are
text(the default),email,telandtextarea. Then place it in the form:<FormField {...form.fields.subject} />insrc/components/sections/contact/ContactSection.tsx. -
To remove a field, delete its entry and its
<FormField … />line. -
Don’t give a real field the name
fax: it is the honeypot’s (Spam).
The newsletter sends only the e-mail and the consent box. To ask for a name too, add a field to SubscribeForm and to
the fields of subscribe in src/lib/actions.ts.
Testing before launch
Section titled “Testing before launch”- Submit each form on your own site after deploying, with a real address: a newsletter sign-up from Home, the sidebar and the band, and a contact message.
- Check the destination (inbox, audience, spreadsheet) and reply to the test message.
- Try a failure on purpose: set a wrong API key, submit, and confirm the visitor sees “Something went wrong” and their text is still there.
The honeypot stops the usual bots: every form carries a hidden field named fax that a person never sees; a bot that
fills it is shown “Thank you” and nothing is sent. If you start getting spam anyway, put a service in front through the
webhook provider (Formspree, Web3Forms and Basin all include spam filtering), use Mailchimp’s double opt-in
(MAILCHIMP_STATUS=pending), or add a captcha to the form component.
Privacy and consent
Section titled “Privacy and consent”Submissions go only where you point them; nothing is sent anywhere else, and the site itself stores nothing. The
newsletter forms in the sidebar and the band carry a consent line that links your Terms of Service and Privacy Policy;
Home’s hero form has none. The legal texts are generic samples with placeholders ([Your Company Name] …): fill them in
and make the Privacy Policy say how you handle subscribers and messages before you collect any
(Editing the content).
Mailchimp adds new contacts as transactional unless you set MAILCHIMP_STATUS: they can get your replies, not your
campaigns. A newsletter needs consent to send to, so set pending (Mailchimp emails a confirmation link first: double
opt-in, the safest choice) or subscribed (only if your form’s wording is a clear opt-in where you publish). The
provider applies to both forms, so with Mailchimp the people who write to you also land in the audience, tagged “New
contact message”; if you don’t want that, send the contact form elsewhere with a webhook or Resend instead.