Adding Formspree Contact Form to Hugo website
Formspree is a form backend, API and email service for HTML & Javascript forms. It’s a simple way to embed custom “contact us” forms on a static website, like Hugo. I’d like to add a reCAPTCHA to the form so I don’t recieve too much spam mail. It’s a simple process, but I’ll go through the steps in how I set it up for this Hugo website. And you can see my contact form in action right on this site.
Formspree Signup
The first step in using a free form is to sign up at https://formspree.io/register
If this is your first time signing up, you should immediately be taken to a Form details for a new form page, but if not you can click add new form on the https://formspree.io/forms page, provide a form name, project name and email and click create form.

First Formspree form
The formspree url can be posted right into your html form post attribute. This is listed as your Formspree endpoint where it directs you to you “Place this URL in the action attribute of your form.”
this URL action can be added to your contact form page
|
|
At this point the form should work!
But I would also like to add a reCAPTCHA with this form!
Go to https://www.google.com/recaptcha/admin and registering a new site.

Registering a new site for reCAPTCHA
Add a lable, recaptcha type ( chose reCAPTCHA v3, you can see more on Introducing reCAPTCHA v3), domain, owner, accept the terms of service and click submit
Expand the reCAPTCHA keys and take note of them. You’ll need the private key for formspree and the site key for your hugo shortcode.

Attaining reCAPTCHA site and secret keys
Adding reCAPTCHA secret key to Formsspree form
Go to the setting of your Formspree form, enable reCAPTCHA and past the secret key into the field:

Adding reCAPTCHA secret key to Formspree form
Adding reCAPTCHA site key to Hugo shortcode
A shortcode in the Hugo static site generator is a reusable piece of code that you can use as a template in your content markdown files. In the gohugo-theme-ananke theme for hugo there is a predefined shortcode that we can modify to add a recaptcha to our contact form. The initial file is locatee in the themes > layouts > shortcoes > form-contact.html. Copy this from the themes folder into your site’s layouts > shortcodes folder. Then you can modify this file. In line 17 “,” you need to replace the text above, “YOURRECAPTCHASITEKEYGOESHERE” with your key from the google reCAPTCHA admin screen.
|
|
Testing the form:
Here is a screenshot of the contact form on bogdanworks.com:

Contact form on bogdanworks.com
Clicking submit sends you to the reCAPTCHA where the user has to confirm they are not a robot.

Testing reCAPTCHA in form
After selecting all images with traffic lights, we get a confirmation page!

reCAPTCHA confirmation page
And I received an email!

Email sent to me
And there you have it folks! Go ahead, contact me!