# Forms (Inquiries, Viewings, Valuations, Newsletter)

## Forms

**Files:** `src/config/config.toml`, form fields in content files · **Skill level:** Beginner

Lotline is a static site, so it has no server of its own to receive messages. Each form sends its answers to a form service you pick, which emails them to you or keeps them in a dashboard. You set that service once in `config.toml`, and every form on the site uses it.

### The Forms And Where They Send
| Form | Where it shows | Fields are in | Sends to |
| --- | --- | --- | --- |
| Inquiry | `/` (Home 1), `/about/`, `/services/` and every service page | `src/content/sections/english/enquiry-section.md` (or a page's `enquirySection` block) | `contactFormAction` |
| Rental valuation request | `/home-3/` | the `enquirySection` block in `homepage/english/home-3.md` | `contactFormAction` |
| Viewing request | every property page | `enquirySection` in `src/content/properties/english/-index.md` | `contactFormAction` |
| Development sign-up ("Join the interest list") | every development page | `enquirySection` in `src/content/developments/english/-index.md` | `contactFormAction` |
| Valuation request | `/valuation/` | `src/content/sections/english/valuation-section.md` (or `valuationSection` in `pages/english/valuation.md`) | `contactFormAction` |
| Contact | `/contact/` | `contactPage.form` in `src/content/contact/english/-index.md` | `contactFormAction` |
| Job application | job pages, and `/careers/#apply` when `general: true` | `application.form` in `src/content/careers/english/-index.md` | `contactFormAction` |
| Newsletter signup | the `pine` footer | `subscription` in `src/i18n/en.json` | `[settings.subscription] formAction` (Mailchimp) |

Every form except the newsletter goes through the same provider, `contactFormProvider`. Each of them sets its own `emailSubject`, so you can tell a viewing request from a valuation in your inbox.

Some forms send one extra hidden value, so you know what the visitor was looking at:

| Form | Hidden field |
| --- | --- |
| Viewing request | `property`: the listing's title |
| Development sign-up | `development`: the development's name |
| Job application | `role`: the job title. `{role}` in its `emailSubject` is filled in too |

<div class="border border-dark">
  ![The valuation request page with the form card](/images/lotline/valuation.jpg)
</div>

### Connect The Forms
The theme ships with placeholder addresses. Until you replace them, messages go nowhere. `npm run dev` shows a notice inside each form, and both `npm run dev` and `npm run build` print a `[forms]` warning in the terminal. Visitors to a deployed site never see the notice, so read the terminal before you deploy.

Pick a provider and set both lines in `[settings]` of `config.toml`:

<Tabs>
  <TabItem label="Formsubmit (default)">

    Free, with no account. Messages arrive by email.

    ```toml
    [settings]
      contactFormAction   = "https://formsubmit.co/you@your-domain.com"
      contactFormProvider = "formsubmit.co"
    ```

    The first message sets off an **activation email** from Formsubmit. Open it and confirm, or later messages won't arrive.

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

    Create a form at [formspree.io](https://formspree.io/) and copy its endpoint. Messages show up in your Formspree dashboard, and Formspree can email them to you.

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

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

    Only when the site is hosted on Netlify. Netlify finds the forms when you deploy.

    ```toml
    [settings]
      contactFormAction   = "/"
      contactFormProvider = "netlify"
    ```

    Turn on form detection in the Netlify dashboard (**Forms**), deploy, and send a test message. Submissions show up in the dashboard and can be forwarded by email.

  </TabItem>
</Tabs>

After launch, send one real message from each form on the live site and make sure it lands.

<Aside type="caution">
  The forms post to the real address even while you work with `npm run dev`.
  Put in your own address before you test.
</Aside>

### The Newsletter (Mailchimp)
The signup row sits at the top of the `pine` footer, the one Home 2 uses. The other footers have no signup.

<Steps>

1. In Mailchimp, open **Audience**, then **Signup forms**, then **Embedded forms**, and copy the URL in `<form action="...">` from the embed code.
2. Paste it as `formAction` in `[settings.subscription]` of `config.toml`, in place of the placeholder with `YOUR_USER_ID` and `YOUR_LIST_ID`.
3. The embed code writes `&amp;` between parameters. Change each one to a plain `&`.

</Steps>

```toml
[settings.subscription]
  enable     = true # false hides the signup form
  title      = ""   # empty: subscription.title in src/i18n/<language>.json
  note       = ""   # empty: subscription.note (the consent line under the field)
  formAction = "https://your-account.us1.list-manage.com/subscribe/post?u=YOUR_USER_ID&id=YOUR_LIST_ID&f_id=YOUR_FORM_ID"
  mailchimpTagValue = "" # optional Mailchimp tag id added to every signup
```

Mailchimp's bot field is added for you from the `u` and `id` in the URL. The form's title, consent line and messages (sending, success, already subscribed, errors) are in `subscription` of `src/i18n/<language>.json`. `title` and `note` in `[settings.subscription]` replace them in every language, which suits a site with one language.

### Change The Fields
Every form except the newsletter is written the same way: a `form` with an `emailSubject`, a `submitButton`, an optional `note`, and a list of `inputs`. Here is part of the general inquiry form in `src/content/sections/english/enquiry-section.md`:

```yaml
form:
  emailSubject: "New inquiry from the website" # subject of the email you receive
  submitButton:
    enable: true
    label: "Send my request"
    variant: "accent"
  inputs:
    - label: "Your name"
      name: "name"              # the field name in the message you receive
      placeholder: "First and last name"
      type: "text"
      required: true
      halfWidth: true           # two fields per row on wider screens
    - label: "Preferred neighborhood"
      name: "neighborhood"
      placeholder: "Pick a neighborhood"
      halfWidth: true
      dropdown:
        type: "select"
        source: "areas"         # one option per neighborhood, then the items below
        items:
          - label: "Not sure yet"
            value: "Not sure yet"
```

| Field type | How to write it |
| --- | --- |
| Text | No `type`, or `type: "text"` |
| Email, phone, number, date, web address | `type: "email"`, `"tel"`, `"number"`, `"date"` or `"url"` |
| Long text | `tag: "textarea"` and `rows` |
| Radio buttons | `type: "radio"`, one item per choice, with the same `name` and `group`. The first one carries `groupLabel`, the question. The valuation form's "Selling or renting out" works this way |
| Checkboxes | `type: "checkbox"`, one item per choice, with a shared `group` |
| Dropdown | `dropdown:` with `type` (`select` or `search`) and `items` (`label`, `value`, optional `selected` and `hint`). `source: "areas"` adds one option per published neighborhood before your items |

Other options: `placeholder`, `required`, `defaultValue`, `value`, `checked` and `id`. The full list is `inputFieldSchema` in `src/sections.schema.ts`. A dropdown item's `hint` shows a line of Markdown under the field while that option is chosen.

A page block such as `enquirySection` in `properties/english/-index.md` replaces the whole `inputs` list when it has one, because lists are replaced, not merged. Copy the full list when you change one field.

### Success And Error Messages
The last two items of `inputs` are not fields. The item with `note: "success"` holds the message shown after the form is sent, and the one with `note: "deprecated"` holds the message shown when sending fails:

```yaml
    - note: "success" # shown after the form is sent
      content: "Thanks, we've got your request. An agent will call or email you within one business day."
    - note: "deprecated" # shown when sending fails
      content: "That didn't send. Please try again, or email us at {email}."
```

`{phone}` and `{email}` are filled in from `[business]` in `config.toml`. Make the success message a promise you keep: "within one business day" is a sample. The field error text ("Check this field.") and the sending label are in `form` of `src/i18n/<language>.json`.

Without JavaScript, every form still sends. It posts straight to the provider, which shows its own confirmation page.

### Spam Protection
Every form except the newsletter has two traps, with no captcha for visitors to solve:

- **A hidden field** that people never see but bots fill in. Its name matches your provider: `_honey` (Formsubmit), `_gotcha` (Formspree) or `bot-field` (Netlify).
- **A time trap.** A form sent less than 4 seconds after the visitor started on it is dropped without a request.

The newsletter uses Mailchimp's own hidden bot field. Your provider may filter spam on top of this, so check its settings.

### Privacy
The contact and job forms have a `note` that links to your privacy policy. Keep it, add one to the other forms if your region expects it, and name your form provider in `src/content/pages/english/privacy-policy.md`.

The section files have no schema, so `npm run astro-check` doesn't report a mistyped option in them. Open each form you changed, fill it in, and send a test.

### Do It With AI
```text
Connect my forms to [Formsubmit with EMAIL | Formspree with form ID | Netlify Forms]: set
contactFormAction and contactFormProvider in src/config/config.toml following its comments. Set
the Mailchimp URL [URL] as formAction in [settings.subscription], with every &amp; changed to &.
Then run npm run dev and tell me if any [forms] warning is left.
```

```text
Change the viewing request form in the enquirySection block of
src/content/properties/english/-index.md to ask for: [FIELDS]. Keep the two message items at the
end of inputs (note: "success" and note: "deprecated"). Make the same change in the French and
Arabic files, with the labels translated.
```