# Forms (Contact, Consultation, Newsletter)

## Forms

**Files:** `src/config/config.toml`, form fields in content files, `src/i18n/<lang>.json` · **Skill level:** Beginner

Covena's forms send to a form service you choose: Formsubmit, Formspree or Netlify Forms. The site itself stores nothing and needs no server. Until you connect a service, every form runs in **demo mode**: it checks the fields, then tells the visitor that nothing was sent.

<div class="border border-dark">
  ![The Covena consultation form](/images/covena/consultation.jpg)
</div>

### The Forms And Where Their Fields Are
| Form                                      | Where it shows                                         | Fields and labels                                               |
| ----------------------------------------- | ------------------------------------------------------ | --------------------------------------------------------------- |
| Contact form ("Get in touch")             | Home 1 and most inner pages                            | `form` in `src/content/sections/<language>/contact-split-form.md` |
| Contact page form                         | `/contact/`                                            | `form` in `src/content/contact/<language>/-index.md`            |
| Consultation form                         | `/consultation/`                                       | `form` in `src/content/consultation/<language>/-index.md`       |
| Callback form ("Ask us to call you back") | Home 3                                                 | `form` in `src/content/sections/<language>/contact-callback-panel.md` |
| Job application form                      | Every role page under `/careers/`                      | `application.form` in `src/content/careers/<language>/-index.md` |
| Newsletter (footer)                       | The `columns-light` footer (Home 2)                    | `[settings.subscription]` in `config.toml`                      |
| Newsletter (panel)                        | `/insights/`                                           | `src/content/sections/<language>/newsletter.md`                 |

The first five share one endpoint. The two newsletter forms are set up separately.

### Connect The Forms
Set the endpoint and the service in `[settings]` of `src/config/config.toml`:

```toml
[settings]
  contactFormAction   = "" # empty = demo mode
  contactFormProvider = "formsubmit.co" # formspree | formsubmit.co | netlify
```

<Tabs>
  <TabItem label="Formsubmit">

    ```toml
    contactFormAction   = "https://formsubmit.co/you@yourfirm.com"
    contactFormProvider = "formsubmit.co"
    ```

    No account needed. Formsubmit emails you the first time a form is sent, to confirm the address. Submissions arrive as a table in your inbox.

  </TabItem>
  <TabItem label="Formspree">

    ```toml
    contactFormAction   = "https://formspree.io/f/your-form-id"
    contactFormProvider = "formspree"
    ```

    Create a form in your Formspree account and copy its address.

  </TabItem>
  <TabItem label="Netlify Forms">

    ```toml
    contactFormAction   = "/"
    contactFormProvider = "netlify"
    ```

    Works only when the site is deployed on Netlify. Turn on form detection in your Netlify site settings, and submissions appear under **Forms**.

  </TabItem>
</Tabs>

Each form's `emailSubject` becomes the subject line of the email you receive, so you can tell the forms apart: "New consultation request from the Covena Law website", "New callback request…" and so on.

<Aside type="caution" title="Send a real test">
  After you connect a form, deploy the site, send a test from the live page
  and check that it arrives. On the dev server, an empty `contactFormAction`
  shows a note telling you which setting to fill in. A built site only says
  "This is a demo form, so nothing was sent."
</Aside>

### Send One Form Somewhere Else
Add `action` to that form's block. It overrides `contactFormAction` for this form only. The content files have a commented line ready:

```yaml
# src/content/consultation/english/-index.md
form:
  action: "https://formspree.io/f/another-form-id"
  emailSubject: "New consultation request from the Covena Law website"
```

The service setting (`contactFormProvider`) still applies, so use the same service for every form.

### The Newsletter Forms
**Footer form** (the `columns-light` footer on Home 2). It sends to Mailchimp:

```toml
[settings.subscription]
  enable            = true
  title             = "" # empty uses footer.newsletterTitle in src/i18n/<lang>.json
  note              = "" # empty uses subscription.description in src/i18n/<lang>.json
  formAction        = "" # your Mailchimp form action
  mailchimpTagValue = "" # optional numeric Mailchimp tag ID
```

To find `formAction`: in Mailchimp, open **Audience > Signup forms > Embedded form** and copy the address in `<form action="...">`. The form signs people up without leaving the page. Set `enable = false` if you don't send a newsletter.

**Panel on `/insights/`**. It has its own settings in `src/content/sections/<language>/newsletter.md`:

```yaml
formAction: "" # your email service's form action
emailFieldName: "email" # use the exact field name your service expects, such as EMAIL
hiddenFields: [] # extra fields your service needs, as name and value pairs
```

Never put a private key or password in `hiddenFields`: the page shows them to anyone who views its source. Both newsletter forms run in demo mode while `formAction` is empty.

### Change The Fields
Each form lists its fields under `inputs`. Edit the labels, add fields or remove them, in every language:

```yaml
inputs:
  - label: "Full name"
    name: "Full name" # the name you see in the email
    required: true
  - label: "Email"
    name: "Email"
    type: "email"
    required: true
    halfWidth: true # half the row, next to the following field
  - label: "Practice area"
    name: "Practice area"
    placeholder: "Choose one"
    dropdown:
      type: "select"
      items:
        - { label: "Employment", value: "Employment" }
        - { label: "Not sure yet", value: "Not sure yet" }
  - label: "How can we help?"
    name: "Message"
    tag: "textarea"
    rows: "5"
    required: true
  - label: "I agree that ... as set out in the [privacy policy](/privacy-policy/)."
    id: "home-contact-consent"
    name: "Consent"
    value: "Yes"
    type: "checkbox"
    required: true
```

| Key           | What it does                                                                                       |
| ------------- | -------------------------------------------------------------------------------------------------- |
| `label`       | The text above the field. Markdown links work, as in the consent box                              |
| `name`        | The field name in the email. Keep it the same in every language if you want the emails to match   |
| `type`        | `text` (default), `email`, `tel`, `radio` or `checkbox`                                            |
| `tag`         | `textarea` for a multi-line field, with `rows`                                                     |
| `required`    | `true` makes the field required                                                                    |
| `halfWidth`   | `true` puts the field in half a row on wide screens                                                |
| `placeholder` | Grey text inside an empty field                                                                    |
| `dropdown`    | A list to choose from, with `type: "select"` and `items`                                           |
| `minLength`   | The fewest characters allowed. Text areas default to 10                                            |
| `id`          | A unique id. Give every checkbox its own                                                           |

The button is `submitButton` in the same block. Change its `label` there.

<Aside type="note">
  The job application form asks for a link to a CV or LinkedIn profile, not
  a file upload. Its description tells people they can email their CV
  instead. Change that address (`careers@example.com`) in
  `src/content/careers/<language>/-index.md`.
</Aside>

### Messages
The messages after sending are in `src/i18n/<lang>.json`, in each language:

- `contactForm.success`: "Thanks, we've got your message. We'll be in touch within 2 working days."
- `contactForm.error`, `contactForm.timeout` and `contactForm.submitting`
- `contactForm.validation`: the messages under a field that's empty or wrong ("This field is required.", "Please enter a valid email address." and so on)
- `forms.demo` and `forms.demoLive`: the demo mode notes
- `subscription.*`: the newsletter messages

The success message promises a reply within 2 working days. Change it if your firm works to a different time.

### Privacy
The forms send what visitors type to the service you chose, so:

- Name the service in your privacy policy (`src/content/pages/<language>/privacy-policy.md`).
- Keep a consent checkbox that links to the privacy policy, as the sample forms do.
- Ask only for what you need. People often describe sensitive matters in the message box. Consider adding a line asking them not to send confidential details before you've agreed to act.

### Do It With AI
```text
Connect the Covena forms to Formspree. In src/config/config.toml set contactFormAction to
"[FORMSPREE URL]" and contactFormProvider to "formspree". Send the job application form to
"[SECOND URL]" by adding action to application.form in src/content/careers/<language>/-index.md,
in every language. Set formAction in [settings.subscription] to "[MAILCHIMP URL]". Don't change
the fields. Then run npm run build.
```