Implementing a Contact Form in Hugo with Formspree

Adding a contact form to your Hugo website can significantly improve communication with your visitors. One of the simplest ways to do this is by using Formspree, a service that handles form submissions without needing your own backend. This guide will walk you through the steps to implement a contact form in Hugo with Formspree.

Step 1: Create Your Formspree Account

First, visit Formspree and sign up for a free account. After signing up, create a new form by following the dashboard instructions. You will receive a unique form endpoint URL, which is essential for connecting your Hugo site to Formspree.

Step 2: Add the Contact Form to Your Hugo Site

Next, open the Hugo project directory and locate the page where you want to add the contact form, typically content/contact.md or a similar file. Insert the following HTML code into your page’s content:

<form action="YOUR_FORMSPREE_ENDPOINT" method="POST">
  <label for="name">Name:</label>
  <input type="text" id="name" name="name" required><br>

  <label for="email">Email:</label>
  <input type="email" id="email" name="_replyto" required><br>

  <label for="message">Message:</label>
  <textarea id="message" name="message" required></textarea><br>

  <button type="submit">Send</button>
</form>

Step 3: Replace the Endpoint URL

Replace YOUR_FORMSPREE_ENDPOINT with the URL provided by Formspree when you created your form. It should look something like https://formspree.io/f/mnqvxyz.

Step 4: Style and Test Your Form

You can add CSS to style your form to match your website’s look. Once styled, test the form by submitting a message. You should receive the email at your registered address through Formspree. Ensure that spam filters do not block the emails.

Additional Tips

  • Use CAPTCHA or other spam prevention methods if needed.
  • Customize the success message or redirect users after submission.
  • Check your Formspree dashboard for submission analytics.

Implementing a contact form with Formspree in Hugo is straightforward and effective. It allows you to maintain a static site while still providing visitors with a way to reach you easily.