Skip to content
Sign inJoin waitlist

Forms — Compose Digi Next.js

The contact form of this Next.js template works as soon as you run it: “Send message” on the Contact page.

It is one form, sent to one server action. It checks the names and the e-mail, shows a spinner on its button 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.

  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 project 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.

  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 (and its optional FORM_WEBHOOK_SECRET), Mailchimp consent settings and how to write your own provider are in Forms reference.

The contact form (title “New contact request”):

Field Name it arrives under Required
First Name (placeholder “First name”) first-name yes
Last Name (“Last name”) last-name yes
Email (“your@company.com”) email yes, and it must look like an e-mail address
Phone Number (“+1(555) 000-0000”) phone
Message (“Tell us about your project”) message
Services: a checkbox per service services (a list of the ticked services)

The labels sit above the fields. First and Last Name sit side by side from tablets up (one under the other on phones); Email, Phone Number, the message and the services each take a full row, then “Send message” across the whole width. When a required field is empty or the e-mail isn’t an address, the first such field gets the focus and each one shows its message (“Please enter your first name.”, “Please enter your last name.”, “Please enter a valid email address.”) until it is changed.

The services are the names in src/content/collections/services.ts, round checkboxes in two columns from tablets up: add, rename or remove a service and the checkboxes follow. The visitor can tick several or none.

Resend puts the sender’s first and last name after the title in the email’s subject (“New contact request — Jane Smith”) and sets the reply address to the sender’s e-mail. Mailchimp stores the names as FNAME and LNAME, tags the contact with the title and keeps the rest as a note (to tag contacts with the services they ticked too, add "services" to tagFields in src/lib/forms/providers/mailchimp.ts). A webhook receives every field of the form, as "" when left empty (the services as a list, [] when none), with its label.

The title (“Get in touch. Stay connected fast.”), the lead, the labels, placeholders, error messages, the button’s three texts (“Send message”, “Thank you”, “Something went wrong”) and the title of each submission (notification) are content: contact in src/content/pages/contact.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 contact.form.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 form 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 company:

    company: { name: "company", label: "Company", placeholder: "Your company", type: "text", autoComplete: "organization" },

    The types are text (the default), email, tel, textarea and checkboxes (with options). The fields are laid out by hand, so also place it in the form: add it to the fields type at the top of src/components/sections/ContactSection.tsx and a <FormField {...fields.company} /> line where it should appear.

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

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

  • Submit the form 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: the 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. Say in your privacy policy what happens to what people send you, and keep the destination secure. The form has no consent checkbox: add one if your visitors’ country requires it.

The form doesn’t ask for marketing consent, so if you send it to Mailchimp, keep MAILCHIMP_STATUS at transactional (the default): those contacts can get your replies, not your campaigns.