Eleventy Guide
Add A Contact Form To Eleventy
Step 1: Create a new form endpoint on Fabform
- Sign up or Log in: If you haven’t already, sign up or log in to Fabform.
- Create a New Form: Specify a name for your form. This name will help you identify your form later. Fabform will provide a unique form endpoint URL for your Eleventy form.
Step 2: Prepare your Gatsby contact form for your website
-
Use Boilerplate Code: Fabform provides boilerplate code for a basic contact form with fields for email address, name, and message.
<form accept-charset="UTF-8" action="https://fabform.io/f/{unique-endpoint-generated-on-step-1}" method="POST"><input type="email" name="email" placeholder="Your Email"><input type="text" name="name" placeholder="Your Name"><input type="text" name="message" placeholder="Your Message"><button type="submit">Send</button></form>
Step 3: Create a new blank 11ty site
If you don’t have an existing 11ty site:
-
Clone Eleventy Base Blog: Run the following commands to clone the Eleventy Base Blog repository, navigate into it, and install dependencies:
Terminal window git clone https://github.com/11ty/eleventy-base-blog.git my-eleventy-blogcd my-eleventy-blognpm install -
Start Eleventy Server: Run Eleventy to serve your site locally:
Terminal window npx eleventy --serve
Step 4: Add a Contact Section to your 11ty site
-
Create Contact Section: Create a new folder named
contact
under the root directory of your site. -
Create Markdown File: Inside the
contact
folder, create a new markdown file namedindex.md
. Update its content with the following code block:---layout: layouts/post.njktitle: ContacttemplateClass: tmpl-posteleventyNavigation:key: Contactorder: 4---<form accept-charset="UTF-8" action="https://fabform.io/f/{YOUR_UNIQUE_FORM_ENDPOINT}" method="POST" enctype="multipart/form-data" target="_blank"><input type="email" name="email" placeholder="Your Email"><input type="text" name="name" placeholder="Your Name"><input type="text" name="message" placeholder="Your Message"><button type="submit">Send</button></form>Important: Replace
{YOUR_UNIQUE_FORM_ENDPOINT}
with the form endpoint URL provided by Fabform in Step 1.
Step 5: Run your 11ty site locally to finalize setup
-
Serve Eleventy Site: Run the following command to see your Eleventy form in action at
localhost:8000/contact/
:Terminal window npx eleventy --serve
That’s it! Your 11ty site now integrates with Fabform, allowing you to receive form submissions seamlessly. You can customize the form’s appearance and behavior as needed.
This guide should provide a more detailed and comprehensive walkthrough for setting up a contact form in an Eleventy site using Fabform.