Skip to content

Eleventy ​

Eleventy builds plain HTML, so there's nothing to run when a visitor presses Send. Point the form at BootForm and it is. Everything on this page works with Eleventy as it is installed, with no plugins. The examples were built with Eleventy 3.

Basic form ​

Put the form straight into any page. HTML inside a Markdown file is passed through as it is:

html
---
title: Contact
permalink: /contact/
---

<form action="https://f.bootform.com/{form_id}" method="POST">
  <label for="email">Your email</label>
  <input id="email" name="email" type="email" required>
  <label for="message">Message</label>
  <textarea id="message" name="message" required></textarea>
  <input type="text" name="honeypot" style="position:absolute;left:-9999px" tabindex="-1" autocomplete="off">
  <button type="submit">Send</button>
</form>

Add your own layout to the front matter if your site uses one.

Replace {form_id} with a UUID you generate yourself (the UUID generator gives you one). Send yourself a test message, then claim the form before the site goes live, so nobody else can claim your ID first.

The honeypot field is a spam trap: people never see it, bots fill it in. Keep it positioned off screen as shown, not hidden with hidden or display:none, which some bots know to skip. New forms use the name honeypot; if you renamed yours, use the name in your form's snippet. See Spam protection.

Don't leave blank lines inside the form in a Markdown file. Markdown starts a new paragraph after each one and wraps the next field in a <p> tag. The form still sends, but its spacing changes.

Keep the form ID in a data file ​

If the form appears on more than one page, or you might change it, keep the ID in one place. Every file in _data is available to every page, under the file's name:

json
{
  "bootformId": "{form_id}"
}

Save that as _data/site.json. Then move the form into an include, _includes/contact-form.njk, and read the ID from site:

html
<form action="https://f.bootform.com/{{ site.bootformId }}" method="POST">
  <label for="email">Your email</label>
  <input id="email" name="email" type="email" required>
  <label for="message">Message</label>
  <textarea id="message" name="message" required></textarea>
  <input type="text" name="honeypot" style="position:absolute;left:-9999px" tabindex="-1" autocomplete="off">
  <button type="submit">Send</button>
</form>

Use it on any page with:

liquid
{% include "contact-form.njk" %}

The quotes around the file name are required. That is different from Jekyll, where the name is written without them.

Keep that line at the start of a line in a Markdown file. Eleventy turns off Markdown's indented code blocks, so an indented include is not shown as text as it is in Jekyll, but the start of the form gets wrapped in a <p> tag.

The same line works in a Markdown page and in a Nunjucks (.njk) page. Eleventy reads Markdown files as Liquid first, and an include is read in the language of the page that uses it. The include above only uses syntax that Liquid and Nunjucks share, so it builds the same HTML in both.

A thank-you page ​

By default, a successful submission shows the visitor BootForm's short "Thanks" page. To send them to a page of your own instead, add a _redirect field with the full URL. It has to be on the same site as the form, or it is ignored.

Eleventy has no setting for your site's address, so add it to _data/site.json yourself, with no slash at the end:

json
{
  "url": "https://yourname.github.io",
  "bootformId": "{form_id}"
}

Then add this line inside the form, in the include:

html
<input type="hidden" name="_redirect" value="{{ site.url }}{{ '/thanks/' | url }}">

and create the page it points at, thanks.md:

markdown
---
title: Thanks
permalink: /thanks/
---

Thanks, your message is on its way. We'll reply within a day.

The url filter is built in. It adds your pathPrefix in front of the path, and site.url puts your address in front of that. On GitHub Pages a project site (anything but yourname.github.io itself) is served from a subpath, and pathPrefix has to match it. Set it in eleventy.config.js:

js
export default function (eleventyConfig) {
  return {
    pathPrefix: "/your-repo-name/",
  };
}

With that, the built field holds https://yourname.github.io/your-repo-name/thanks/. Without a pathPrefix it holds https://yourname.github.io/thanks/, which is what you want on your own domain: set url to the domain and leave pathPrefix out.

If you already have a config file, add pathPrefix to the object it returns. You can also pass it when you build, with npx @11ty/eleventy --pathprefix=your-repo-name.

Sending without leaving the page ​

To submit in the background and show a message in place, add the script from the Vanilla JS guide's AJAX section to the include. It sends Accept: application/json and gets 200 {"ok":true} back. Eleventy copies a <script> tag into the page as it is. Leave _redirect out in that case; it only applies to a classic form post.

File uploads and the moderated feed ​

Both work on an Eleventy site exactly as in plain HTML: see Vanilla JS, file upload and Vanilla JS, moderated content feed. A file upload needs the form claimed first.

Common problems ​

The build stops with illegal file path "undefined". The include name has no quotes around it. Write {% include "contact-form.njk" %}, not the Jekyll form without quotes.

Some fields are wrapped in <p> tags and the form's spacing looks wrong. There are blank lines inside the form, in a Markdown file or in an include used from one. Remove them.

The page shows {# ... #} as text above the form. That is a Nunjucks comment in an include used from a Markdown page. Liquid doesn't know that syntax and prints it. Delete the comment.

The built form's action ends in f.bootform.com/, with no ID. The include didn't find site.bootformId. Check the file is _data/site.json and the key is spelled the same in both places. Capital letters count: bootformID is a different key.

After sending, the visitor lands on a 404. The _redirect URL is wrong, almost always because pathPrefix doesn't match where the site is served. Open the built page's source and check the value of the _redirect field. A double slash after the domain means url ends in a slash.

The build stops with Unexpected token 'export' in the config file. Your package.json doesn't say "type": "module". Rename the file to eleventy.config.mjs, or write module.exports = in place of export default.

The _redirect value contains something like C:/Program Files/Git/. You passed --pathprefix=/your-repo-name/ in Git Bash on Windows, which rewrites an argument that starts with a slash. Leave the slashes off, or set pathPrefix in the config file.

You sent a test message but no email arrived. The form isn't claimed yet. Nothing is delivered until it is; claim it and the messages sent so far are delivered. Held messages are kept for 48 hours.