Hugo guide
Add a contact form to a Hugo site
Hugo builds static HTML, so a form needs somewhere to post. Keep the key in your site config, add one partial, and every submission is 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 the site config
hugo.toml[params] formcrateKey = "YOUR_FORM_KEY"
3Create a partial
layouts/partials/contact-form.html<form action="https://www.formcrate.dev/api/submit/{{ site.Params.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="{{ "thanks/" | absURL }}" /> <button type="submit">Send</button> </form>4Include it in a layout
Add it to the template for your contact page. Partials can't be called from Markdown content directly; wrap it in a shortcode if you want that.
layouts/_default/contact.html (or any template){{ partial "contact-form.html" . }}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
- Create
content/thanks.mdfor the redirect, or remove theredirectToline to use Formcrate's confirmation page. - Using
config.yaml? Putparams: { formcrateKey: YOUR_FORM_KEY }there instead.
Get your Hugo form working
Free for 500 submissions a month. Spam filtering, email alerts and an inbox included. No card required.