Skip to content
Sign inJoin waitlist

Forms — Balancee Next.js

The two forms of this Next.js template work as soon as you run them: the contact form (“Tell us about your project.”) on the Contact page and the Services page, and the newsletter box in the footer of every page (“Never Miss an Update — Subscribe!”).

Each form is sent to its own server action (sendContact and sendNewsletter in src/lib/actions.ts). They check the e-mail, show a spinner on the button while sending, say “Thank you” and clear the fields, keep what the visitor typed when something fails (“Something went wrong”), and drop spam with a hidden honeypot field. The contact form works without JavaScript too.

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.

  1. Copy the example settings:

    Terminal window
    cp .env.example .env.local
  2. Choose one:

    You want Set
    An email for every submission FORM_PROVIDER=resend + RESEND_API_KEY, FORM_EMAIL_TO, FORM_EMAIL_FROM
    It in your CRM, Slack, a spreadsheet, a booking tool… FORM_PROVIDER=webhook + FORM_WEBHOOK_URL (Zapier, Make, n8n, Formspree, your own API)
    The sender in a Mailchimp audience FORM_PROVIDER=mailchimp + MAILCHIMP_API_KEY, MAILCHIMP_AUDIENCE_ID

    Several at once work: FORM_PROVIDER=resend,mailchimp.

  3. Restart npm run dev and send a test from the Contact page and from the footer.

  4. Put the same variables in your host’s dashboard before deploying. .env.local is not uploaded.

Details for each provider, what it receives, the webhook payload, Mailchimp consent settings and how to write your own provider are in Forms reference.

The contact form (the notification’s title is “New message from the Balancee contact form”):

Field Name it arrives under Required
Name (placeholder “Jane Smith”) Name yes
Company (“Balancee & Co.”) Company yes
Email (“jane@example.com”) Email yes, and it must look like an e-mail address
Phone (“Phone Number”) Phone
I’m interested in … — a choice of one service, written out as radio buttons Service (the chosen service, or empty)
Tell us about your project. (“Write something concise …”) Message

The labels sit above the fields. From tablets up the fields sit in two columns; the services and the message take a full row, then the Submit button over the line “By submitting, you agree to our Terms of Service and Privacy Policy”. When a required field is empty or the e-mail isn’t an address, the first failing field gets the focus and every failing field shows its message (“Please fill out this field.” or “Please enter a valid email address.”).

The eight choices of “I’m interested in …” are the names of the services, written out in contactForm.fields.service.options in src/content/pages/shared.ts (they are not read from the collection): when you add, rename or remove a service, change them there too. The visitor picks one or none.

Resend puts the sender’s name after the title in the email’s subject (“New message from the Balancee contact form — Jane Smith”) and sets the reply address to the sender’s e-mail. Mailchimp stores the name as FNAME and keeps the rest as a note. A webhook receives every field of the form, as "" when left empty, with its label.

One field, Email, in the footer. It is required and must look like an e-mail address; the button reads “Join Now”, then “Thank you” or “Try again”. Its submissions carry form: "newsletter" and the title “New newsletter subscriber” (sendNewsletter in src/lib/actions.ts). The texts of the box are footer.newsletter in src/content/site.ts.

The box asks people to subscribe, so if you send it to Mailchimp, set MAILCHIMP_STATUS to pending (double opt-in) or subscribed; with the default transactional the contact can get your replies but not your campaigns (Forms reference). The contact form doesn’t ask for marketing consent: with pending or subscribed it would also add its senders to your list, so tell people, or use a webhook for the contact form.

The labels, placeholders, error messages, the button’s three texts (“Submit”, “Thank you”, “Something went wrong”) and the title of each submission (notification) are content: contactForm in src/content/pages/shared.ts. The intro of the form on the Services page is contactSection in service.ts. A field arrives at your provider under its name, so keep the names you already map somewhere.

The server action (sendContact in src/lib/actions.ts) sends every field listed in contactForm.fields and checks the required ones again on the server, so the list in the copy is the place to edit:

  • To make a field required, set required: true on it and give it an error message. The browser checks it before sending and the server checks it again. No asterisk is shown: say it in the label if you want one. A required field must be on the page: if it is only in the list, every submission fails.

  • To add a field, add an entry, for example the visitor’s city:

    city: { name: "City", label: "City", placeholder: "London", type: "text", autoComplete: "address-level2" },

    The types are text, email, tel, textarea and radios (with options). The fields are laid out by hand, so also place it in the form: <FormField {...fields.city} /> in src/components/sections/ContactForm.tsx (add className="md:col-span-2" for a full-width one).

  • To remove a field, delete its entry and its <FormField … /> line. Keep the e-mail: every provider needs it.

  • Don’t give a real field the name fax: it is the honeypot’s (Spam).

  • Submit both forms on your own site after deploying, with a real address.
  • Check the destination (inbox, spreadsheet, audience) and reply to the test.
  • 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: 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 add a captcha to the form component.

Submissions go only where you point them; nothing is sent anywhere else. The contact form collects a name, a company, an e-mail address and possibly a phone number: say what happens to them in your privacy policy (src/content/collections/legal.ts), keep the destination secure, and check what your country’s rules ask of you. The forms have no consent checkbox: add one if your visitors’ country requires it.