Writing8 of 9

Forms

The contact form, and how to make your own. Forms are a short file each; sending them needs a small program on your server.

2 min read

On this page

The template comes with a contact form on /contact/:

The contact page: fields for your name, your email, what it's about and a message

How a form is made

Each form is a file in forms/. Here's forms/contact.yaml:

The file forms/contact.yaml: title, to, subject, reply_to, four fields, the button's text and a mailto address

Key What it's for
to The email address submissions are sent to. Change this to yours.
subject The email's subject. {{ .name }} puts in what was typed in the name field.
reply_to The field holding the sender's address, so replying to the email replies to them.
fields The questions, in order (below).
submit The button's text.
success Optional: a page to send people to after sending, such as /contact/thanks/. Without it, a thank-you appears in place of the form.
mailto An address shown to people whose browser can't send the form, so they can email you instead.
store true also keeps each submission in a file on your server.

Fields

Each field has a name (letters, no spaces) and a label (what people see):

fields:
  - { name: name, label: Your name, required: true, max: 120 }
  - { name: email, type: email, label: Your email, required: true }
  - { name: topic, type: select, label: About, options: [A question, Feedback] }
  - { name: message, type: textarea, label: Message, required: true }
  • type is text (the default), email, url, tel, textarea (several lines), select (a choice from options) or checkbox.
  • required: true means it must be filled in.
  • max limits how long the answer can be.

Put a form on a page

Add form: with the form's file name to the page's front matter:

---
title: Book a table
form: booking
---

Tell us when you'd like to come.

That shows forms/booking.yaml under the page's text. If a form doesn't make sense (no recipient, a choice with no options), the build stops and says why.

Ready-made forms

The contact-forms pack adds three more forms, and a section to show any form with your details beside it:

hotdog-cms pack add contact-forms
  • forms/quote.yaml: a quote request: what's needed, by when, a budget and the details.
  • forms/booking.yaml: a booking request: which day, what time of day and how many people. It asks; you confirm by email.
  • forms/signup.yaml: a mailing list sign-up, with a box people tick to say yes. Say in your privacy notice what you do with the addresses.

The forms are your site's own once they're added: change them like any form. Upgrading or removing the pack leaves them alone, and if your site already has a form with one of those names, yours is kept.

They send to you@example.org until you set to and mailto to your own address. hotdog-cms check warns about any form that still does, the contact form included, so you see it before you publish.

Then add a Contact form section to a page, in the editor or in the front matter. form is the name of any form in forms/:

---
title: Catering
sections:
  - contact-form:
      heading: Ask for a quote
      form: quote
      email: hello@example.org
      phone: (217) 555-0142
      address: |
        12 Main Street
        Springfield, IL 62701
      note: We answer within one working day.
---

The Contact form section: the quote request form, with the bakery's email, phone, address and when it answers in a panel beside it

Sending submissions

Your site is plain files, and plain files can't send email. Forms are sent by the endpoint, a small program that runs on your web server beside the site. It checks each submission (that it came from your site, isn't a robot, isn't too long) and emails it to you.

Setting it up is a job for whoever runs your server: see Forms and search on your server. Until it's running, people can still reach you through the mailto address.

In the editor, the Forms page edits forms with a form of its own, and can show stored submissions. See The editor.

↑↓ moveEnter openEsc close