Skip to content
Formlander

Hugo contact form on your own server

Add a contact form to a Hugo site with a partial and a shortcode. The form posts to a Formlander server that you host.

Hugo builds static files, so a Hugo site has nothing that can receive a form. Formlander is a form backend that you run on your own server. Put the form in one partial, and use that partial in any template or content file.

  1. A Formlander server. The deployment page has the install command.
  2. A form in the Formlander dashboard with the address contact. Put the domain of your baseURL in Allowed sites. Add localhost to test with hugo server.
  3. The Endpoint of the form. Copy it from the page of the form in the dashboard. It contains the token of the form, which is public.
layouts/_partials/contact-form.html
<form action="https://forms.example.com/forms/contact/submit?token=YOUR_TOKEN" method="post">
<input type="hidden" name="_success_url" value="{{ "thanks/" | absURL }}">
<input type="text" name="__fl_hp" value="" tabindex="-1" autocomplete="off" aria-hidden="true" style="position:absolute;left:-9999px">
<label for="name">Name</label>
<input type="text" id="name" name="name" autocomplete="name" required>
<label for="email">Email</label>
<input type="email" id="email" name="email" autocomplete="email" required>
<label for="message">Message</label>
<textarea id="message" name="message" rows="5" required></textarea>
<button type="submit">Send</button>
</form>

Replace the action value with your Endpoint. Set baseURL to the full URL of your site. absURL uses it to make a full URL. Make the thank-you page, for example content/thanks.md.

Call the partial where you want the form:

{{ partial "contact-form.html" . }}

A content file needs a shortcode. Make one that calls the partial:

layouts/_shortcodes/contact-form.html
{{ partial "contact-form.html" . }}

Then use it in Markdown:

content/contact.md
---
title: Contact
---
Send us a message.
{{< contact-form >}}

The shortcode works with the default Hugo settings. Do not paste the partial into a Markdown file. Hugo leaves raw HTML out by default, and absURL does not run there.

Before Hugo 0.146, name these folders layouts/partials and layouts/shortcodes.

The browser posts the form to your Formlander server. If the token is right and your site is in Allowed sites, Formlander stores the fields as JSON in its SQLite file. Then it sends the browser to your thank-you page. The _success_url and __fl_hp fields are not in the stored submission.

If the thank-you page is on a site that is not in Allowed sites, Formlander answers 400 and stores nothing. Check this when you change baseURL.

Each submission is in the dashboard. Formlander can forward it by email (SMTP or Mailgun) or to a webhook, with retries.

The __fl_hp input is a honeypot. Spam and security explains it, Allowed sites, the rate limit, and Turnstile.

For Turnstile, add the widget inside the form in the partial. Then edit your form in the dashboard and choose the profile in Captcha.

For fetch, the JavaScript SDK, and file uploads, see Form integration.