Forms — Brickfolio Next.js
The two forms of this Next.js template work as soon as you run it: the contact form on Home (“Let’s Connect”) and the newsletter box in the footer of every page.
Each is sent to a server action in src/lib/actions.ts (sendContact, sendNewsletter). Both check the fields in the browser and again on the server, show a spinner on the button while sending, then “Thank you” or “Something went wrong”, and drop spam with a hidden honeypot field. On success the fields are cleared; on an error the contact form keeps what the visitor typed.
Out of the box, both 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.
The quickest way to receive messages
Section titled “The quickest way to receive messages”-
Copy the example settings:
Terminal window cp .env.example .env.local -
Choose one:
You want Set An email for every message and sign-up FORM_PROVIDER=resend+RESEND_API_KEY,FORM_EMAIL_TO,FORM_EMAIL_FROMThe senders in a Mailchimp audience FORM_PROVIDER=mailchimp+MAILCHIMP_API_KEY,MAILCHIMP_AUDIENCE_ID, andMAILCHIMP_STATUS(below)It in a CRM, a spreadsheet, Slack… FORM_PROVIDER=webhook+FORM_WEBHOOK_URL(Zapier, Make, n8n, Formspree, your own API);FORM_WEBHOOK_SECRETis optionalSeveral at once work:
FORM_PROVIDER=resend,mailchimp. The setting applies to both forms. -
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.
The providers
Section titled “The providers”The providers are in src/lib/forms/providers/, one file each, and FORM_PROVIDER picks them by name
(src/lib/forms/providers/index.ts).
FORM_PROVIDER |
What happens | Variables |
|---|---|---|
console (default, also when the variable is missing) |
Printed to the server log. For development. | — |
resend |
Emails each submission through Resend, with the form’s title as the subject and the sender’s address as the reply address. | RESEND_API_KEY; FORM_EMAIL_TO (one address or several, comma-separated); FORM_EMAIL_FROM, a sender on a domain you verified in Resend, e.g. Brickfolio <forms@yourdomain.com> |
mailchimp |
Adds or updates the sender in a Mailchimp audience, tags them with the form’s title and keeps the submission as a note on their profile. | MAILCHIMP_API_KEY (it ends in your data centre, e.g. -us21), MAILCHIMP_AUDIENCE_ID, MAILCHIMP_STATUS |
webhook |
Posts the submission as JSON to a URL. | FORM_WEBHOOK_URL; FORM_WEBHOOK_SECRET, sent as Authorization: Bearer <secret> |
Another service (Postmark, Brevo, ConvertKit, a database…): copy one of the files, change the request, and add it to
providers in index.ts under a new name. A provider receives the submission below and throws to make the form show its
error.
What the forms send
Section titled “What the forms send”The contact form (form contact, title “New message from the contact form”):
| Field | Name it arrives under | Required |
|---|---|---|
| First name | First Name |
yes |
| Last name | Last Name |
yes |
Email |
yes, and it must look like an e-mail address | |
| Phone number | Phone Number |
yes |
| Message | Message |
no |
The newsletter box (form newsletter, title “New newsletter subscriber”):
| Field | Name it arrives under | Required |
|---|---|---|
| E-mail (placeholder “Enter your email”) | Email |
yes, and it must look like an e-mail address |
A webhook receives:
{ "form": "contact", "title": "New message from the contact form", "submittedAt": "2026-10-27T10:48:23.256Z", "data": { "First Name": "Jane", "Last Name": "Doe", "Email": "jane@example.com", "Phone Number": "+1 555 000 0000", "Message": "Hello!" }, "labels": { "First Name": "First Name", "Last Name": "Last Name", "Email": "Email", "Phone Number": "Phone Number", "Message": "Message" }}Resend’s email lists every filled field as “Label: value”, and the reply goes to the address typed in the form.
Mailchimp and consent
Section titled “Mailchimp and consent”MAILCHIMP_STATUS decides what you may send to the people the forms add: transactional (the default) stores the
contact but they can’t receive your campaigns, pending sends them a confirmation e-mail first (double opt-in), and
subscribed is only for addresses that gave explicit consent. For the newsletter box, pending is the usual choice.
The contact form goes to the same audience when Mailchimp is on. Its name fields are kept in the note; to fill the
audience’s first and last name, add them to mergeFields in src/lib/forms/providers/mailchimp.ts
("first name": "FNAME", "last name": "LNAME"; field names are matched ignoring case). To keep contact messages out of
Mailchimp, use Resend or a webhook for them, or check submission.form in the provider.
Changing the forms
Section titled “Changing the forms”The contact form’s words and fields are contact in src/content/pages/home.ts: the title and text, the fields (each
with its name, label, placeholder, type — text, email, tel or textarea — and required), the button’s
label (submit, “Send message”) and its two messages (success, error). sendContact reads the same list, so a field
you add, remove or make optional there is checked and sent that way on the server too. The first two fields sit side by
side from 810 px (src/components/sections/Contact.tsx).
The newsletter box’s words are footer.newsletter in src/content/site.ts:
| Field | Demo |
|---|---|
title |
“Subscribe to Our Newsletter” |
text |
“Join now and never miss out on our stuff again. Because you are worth it!” |
placeholder |
“Enter your email” (also the field’s name for screen readers) |
submit |
“Subscribe” |
success |
“Thank you” |
error |
“Something went wrong” |
The titles of each submission are set in src/lib/actions.ts. To add a field to the newsletter box, add the input to
NewsletterForm in src/design-system/components/forms/NewsletterForm.tsx and its { name, label } to the fields
list in sendNewsletter; only the fields listed there are sent.
Testing before launch
Section titled “Testing before launch”- Send the contact form and sign up on your own site after deploying, with a real address.
- Check the destination (inbox, audience, spreadsheet).
- Try a failure on purpose: set a wrong API key, send, and confirm the visitor sees “Something went wrong” and the contact form still holds what was typed.
The honeypot stops the usual bots: each 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), or use Mailchimp’s double opt-in.
Privacy
Section titled “Privacy”Messages and sign-ups go only where you point them; nothing is sent anywhere else. The forms collect names, e-mail addresses and phone numbers: say what happens to them in your privacy policy, keep the destination secure, and check what your country’s rules ask of you. The template has no privacy page and no consent checkbox: add them if your visitors’ country requires it (Pages and sections).