Eleventy guide
Add a contact form to an Eleventy site
Eleventy outputs static HTML. Keep your form key in global data, add one include, and submissions are spam-checked and emailed to you.
1Create a form and copy its key
Sign up with Google, create a form and enter the email address that should receive submissions. Copy the form key from the dashboard: it replaces
YOUR_FORM_KEYbelow. The free plan includes 500 submissions a month.2Add your form key to global data
_data/site.json{ "url": "https://yoursite.com", "formcrateKey": "YOUR_FORM_KEY" }3Create an include
_includes/contact-form.njk<form action="https://www.formcrate.dev/api/submit/{{ site.formcrateKey }}" method="POST"> <input type="text" name="name" placeholder="Name" required /> <input type="email" name="email" placeholder="Email" required /> <textarea name="message" placeholder="Message" required></textarea> <input type="text" name="_gotcha" style="display:none" tabindex="-1" autocomplete="off" /> <input type="hidden" name="redirectTo" value="{{ site.url }}/thanks/" /> <button type="submit">Send</button> </form>4Use it in a page
contact.njk--- title: Contact --- {% include "contact-form.njk" %}5Send a test submission
Fill in the form on your site and submit it. The message appears in your Formcrate inbox and arrives by email within a few seconds. Anything that looks like spam goes to the Spam tab instead and isn't emailed.
6Lock the form to your domain
Your key is visible in the page source, which is normal for form backends. In the form settings, add your domain under Domain lock so other websites can't post to your form from the browser.
Tips
- Markdown pages are processed with Nunjucks by default, so the include works in
.mdfiles too.
Get your Eleventy form working
Free for 500 submissions a month. Spam filtering, email alerts and an inbox included. No card required.