--- name: website-contact-form description: > Add a contact form to a new-website site that needs no server and no setup: the visitor fills in a few fields, presses a button, and their own email program opens with a message to the owner, ready to send. Nothing is sent or stored by the site. Adds a form component, its texts in English and German, one small script of the site's own (so a strict Content-Security-Policy holds), and tests/mail-form.spec.ts. The owner's address is always shown under the form for visitors without a mail program or without JavaScript. Run when new-website Q2 asks for a contact form, or later when the owner wants one. Trigger phrases: "contact form", "add a form", "enquiry form", "visitors should be able to write to us", "kontaktformular". Not for newsletter sign-up, file uploads, or anything that has to be stored. --- # Website contact form — the visitor's own mail program sends it Our suggestion for contact on a small site: a short form whose button opens the visitor's own email program with a message to the owner already written. The visitor reads it, presses Send, and it arrives like any other email. There is no server work, no account and no setting behind it. ## Why this form (say this to the owner, in your own words) - **Nothing to set up.** No account, no password or token, no change to the domain's mail settings. It works on any host, today, and on a preview address too. - **No spam through the form.** It sends nothing, so there is nothing for a bot to fill in and fire off: every message needs a real mail account and a person pressing Send. Spam sent straight to the address is another matter, the same as for any address on any site; the form keeps it out of the page as plain text, as the starter's email link does, which stops the simple address collectors. - **No company in between.** The message goes from the visitor's mailbox to the owner's, like any email. So the privacy page needs no paragraph about a service that handles messages: its section on contact by email already covers it (§4). - **The visitor keeps a copy** in their Sent folder, and the owner answers with Reply. And the honest weak spots, so the owner hears them from you first: - **Some visitors have no mail program set up.** Someone who reads mail only in a browser (webmail), or sits at a shared computer, presses the button and gets nothing, or a mail program they never use. That is why the plain address always shows under the form, ready to copy, and the line after the button says to use it if nothing opened. - **The site never learns whether the visitor pressed Send.** A message can be written, opened and then not sent. No form counts sent messages here. If the owner needs either of those solved (messages from every visitor whatever their setup, or a count of them), this is the wrong tool: see §0. ## 0. Is this the right tool? (ask before installing) 1. **Is a form wanted at all?** For a handful of enquiries a year, the plain email link the starter already has (``) does the job. Say so. 2. **Is "the visitor's own mail program sends it" enough?** Yes for nearly every small site. No when the owner must receive messages from visitors who only use webmail, or must know how many were sent. Then say plainly that this skill does not fit, and point to `new-website/references/WEBSITE_ARCHITECTURE.md` Tier 2: a form that sends through a server, which needs a mail service, settings only the owner can create, and a paragraph on the privacy page. Not built by this skill. 3. **Are file uploads or a newsletter sign-up wanted?** Different problems; not this. ## 1. What it adds to the site | File | From this skill's `templates/` | What it is | |---|---|---| | `src/components/MailForm.astro` | `MailForm.astro` | the form, and the address line under it | | `src/components/mail-form-text.ts` | `mail-form-text.ts` | everything the form says, in English and German, and the longest message it takes | | `public/js/mail-form.js` | `mail-form.js` | the script: shows the form, builds the `mailto:` link, opens it | | `tests/mail-form.spec.ts` | `mail-form.spec.ts` | the form as a visitor meets it: the link the button opens (address, subject, every field, encoding), an empty field, labels and keyboard order through any added fields, a hint as the message box's description, the page without JavaScript, a strict Content-Security-Policy, and every text against the site's tone rules | The templates are in this skill's `templates/` folder, beside this SKILL.md; the bundled copy of the skill on a handed-off repo has them too. Install all four. **How it works, in one paragraph.** The owner's address goes into the HTML encoded the way `EmailLink` encodes it (`src/lib/obfuscate.ts`), never as plain text. The script, a file of the site's own under `public/js/` rather than an inline script, so a strict `script-src 'self'` policy lets it run, shows the form, and when the button is pressed decodes the address and opens `mailto:
?subject=…&body=…`. The body starts with the greeting the owner chose (`greeting`), then the visitor's message as typed, less any empty space (spaces, tabs, blank lines) at its very start and end. Every other field the visitor filled in follows as "Label: value", so a field the owner adds later goes into the mail by its label with no change to the script. The language's sign-off ("Kind regards", "Freundliche Grüße") ends it; the visitor's mail program says who they are. Without JavaScript the form stays hidden, since it could do nothing, and the address line under it is what the visitor sees. **The spec needs `toneViolations`** from the site's `tests/_helpers.ts`, the tone rules its pages are held to. A site made from an older starter lacks it, and `npm run check` says `has no exported member 'toneViolations'`. Then first bring that file up to date from the starter's (`new-website/templates/astro/tests/_helpers.ts`): take `toneViolations` and the rules above it, keep the site's own `PAGES`. Take the starter's `tests/tone.spec.ts` with it, so the pages and the form read one list. Before replacing the site's `tone.spec.ts`, compare its rules and its `ALLOWLIST` with the starter's: a word the site added goes into the same place in `_helpers.ts`, or the site loses it. ## 2. Install (on a branch, as a pull request: `AGENTS.md` §2) 1. Copy the four files to the places in §1 (`mkdir -p public/js` first). 2. Put the form on a page, inside that page's ``: ```astro --- import MailForm from '../components/MailForm.astro'; --- ``` Ask the owner for the address. The starter's encoding takes only plain addresses: letters, digits and `. _ % + -` before the `@`, and the build stops with a clear message on anything else. A **new** `/contact` page is a new page: work through `AGENTS.md` §6 (`PAGES`, `llms.txt`, share card, a link to it). One form per page: its ids are fixed. **The subject line** (`subject`, required: the build stops without it). It is the first thing the visitor reads in their mail program, and what stays in their Sent folder. So let it name what they came for, in their words, rather than the website: an architects' office "Anfrage Bauvorhaben", a holiday flat "Booking request", a consultant "Project enquiry". The mail then starts as their own request, not as a message to a website. Take it from the site's offer and the primary action in `CONTENT_GUIDE.md`, in the page's language, and keep it short, about 40 characters, so a mail program's list shows all of it. A page for one offer can pass its own. Propose one or two and let the owner choose: these are their customers' first words to them. The plain address under the form carries the same subject. **The greeting** (`greeting`, required: the build stops without it). The first line of every mail, as the visitor would write it to the owner, punctuation included. Ask the owner whom visitors address, and propose one in the site's form of address: "Sehr geehrte Frau Muster," where one named person answers on a "Sie" site, "Sehr geehrte Damen und Herren," for a firm with no one person, "Hallo Anna," on a "du" site, "Dear Ms Smith," in English. The mail ends with the language's sign-off (`signoff` in `mail-form-text.ts`: "Kind regards", "Freundliche Grüße", no comma). A site that wants another, such as "Viele Grüße", changes it there. The plain address under the form opens a blank mail, with no greeting. 3. **Language.** The form speaks the language of the page it is on, by itself: a page built with `` on an English site gets a German form. `Base.astro` hands the page's language down (`Astro.locals.lang`); on a site with several languages it is the page's locale. `lang="…"` overrides; then set `LANG` in the spec too (step 4). English and German are built in, with no form of address in German, so the form fits a "du" site and a "Sie" site. Any other language: "Add a language" below, first. A form in a language with no texts stops the build. **A site made from an older starter** lacks the line in `Base.astro`. On a site without Astro's language routing, a form without `lang` then stops the build with a message naming the line (with routing, the page's locale stands in). Add `Astro.locals.lang = lang;` after the props in `Base.astro`, and the declaration `declare namespace App { interface Locals { lang?: string } }` to `src/env.d.ts`: create the file from the starter's if the site has none, and keep what a site's own file already declares. Without the declaration, `npm run check` fails on the line. 4. In `tests/mail-form.spec.ts` set `PAGE` (the page with the form), `TO`, `SUBJECT` and `GREETING` (the address, the subject and the greeting from step 2). The spec fails while one is empty, and holds the subject and the greeting to the site's tone rules. `LANG` only if the page passes `lang`. One copy guards one form: with the form on pages in two languages, copy it once per language (`tests/mail-form.de.spec.ts`), each with its own `PAGE`, `SUBJECT` and `GREETING`. 5. **Fields.** The form asks for the message, nothing else: the visitor's name and email address come with their mail, and the form adds the greeting and the sign-off. A field the owner wants, or a hint above the message box: "Adding fields" below. 6. `npm run check && npm test`. ### Adding fields Ask only what the visitor's mail cannot carry and the owner needs to answer: a kind of request, a place, a phone number for a call back. Never a name or an email field: the mail brings both. Each field is one more reason to leave; two or three is plenty. Fields go between `` and ``, and come before the message. A hint goes in the slot `hint`: the form shows it between the message's label and its box, and ties it to the box (`aria-describedby`), so it becomes the box's accessible description. An example, for a building firm: ```astro
What is it about? (optional)

(optional)

For example: what is planned, how far the planning is, when work should start.
``` The mail then reads, between the message and the sign-off: "A new project" and "Town: Bath". The rules behind it, each from a source read on 2026-10-27: - **A choice is radio buttons in a `fieldset`, named by its `legend`.** "Radio button groups should always be grouped using `
`" (W3C WAI, https://www.w3.org/WAI/tutorials/forms/grouping/). The mail carries the ticked option's label alone, not the legend, so write each option to read on its own ("A new project", not "New"). - **Every added field starts empty.** No list (`select`): a drop-down list always has an entry chosen, so an untouched list sends an answer the visitor never gave, a "Please choose" entry included. No box ticked and no text filled in advance. The script sends whatever a field holds, and the spec expects no field line when the visitor adds nothing. - **None ticked in advance.** "Do not pre-select radio options" (GOV.UK Design System, https://design-system.service.gov.uk/components/radios/). Once ticked, a radio cannot be unticked; for an optional choice that costs one line the visitor can delete in their mail program. - **Optional fields say "(optional)"; required ones get no asterisk.** "Never mark mandatory fields with asterisks" (GOV.UK, https://design-system.service.gov.uk/patterns/question-pages/). GOV.UK puts the word in the label; here it goes beside it, in a `span` with class `mail-form-optional` tied to the field with `aria-describedby`, because the mail uses the label's text: "Town: Bath", not "Town (optional): Bath". In a radio group it goes in the `legend`, which the mail never shows. - **A hint shows above the box, never as a placeholder.** Placeholder text disappears as the visitor types; Nielsen Norman Group recommends "clear, visible labels that are placed outside empty form fields" (https://www.nngroup.com/articles/form-design-placeholders/). - **A hint can follow the choice, by CSS alone.** Put one `span` per case in the slot (`………`) and show the one that fits, in the page's `