Skip to content

Hugo ​

Hugo builds plain HTML, so there's nothing to run when a visitor presses Send. Point the form at BootForm and it is. Everything on this page uses Hugo's own templates: no theme, no module and no JavaScript.

Basic form ​

Hugo does not pass a form written in a Markdown file through to the page (the next section shows what happens). Put the form in a shortcode instead. Create layouts/shortcodes/contact-form.html:

html
<form action="https://f.bootform.com/{form_id}" method="POST">
  <label for="email">Your email</label>
  <input id="email" name="email" type="email" required>

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

  <input type="text" name="honeypot" style="position:absolute;left:-9999px" tabindex="-1" autocomplete="off">

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

Then call it from any content file, for example content/contact.md:

markdown
---
title: Contact
---

Send us a message.

{{< contact-form >}}

Replace {form_id} with a UUID you generate yourself (the UUID generator gives you one). Send yourself a test message, then claim the form before the site goes live, so nobody else can claim your ID first.

The honeypot field is a spam trap: people never see it, bots fill it in. Keep it positioned off screen as shown, not hidden with hidden or display:none, which some bots know to skip. New forms use the name honeypot; if you renamed yours, use the name in your form's snippet. See Spam protection.

Recent Hugo versions also accept the folder names layouts/_shortcodes and layouts/_partials. Use whichever your site already has.

Why the form is not in the Markdown file ​

Hugo's Markdown renderer removes raw HTML unless you tell it not to. Paste the form above straight into content/contact.md and the built page has no form at all. Each tag is replaced by a comment, and only the words "Message" and "Send" are left:

html
<!-- raw HTML omitted -->
<p><!-- raw HTML omitted -->Message<!-- raw HTML omitted --></p>
<!-- raw HTML omitted -->

The build also prints a warning that starts with Raw HTML omitted while rendering. A shortcode avoids this, because Hugo inserts its output after the Markdown has been rendered. That is only true for the angle bracket call shown above. The percent call sends the output through Markdown again, and the form is removed like before:

markdown
{{% contact-form %}}

You can switch the filter off for the whole site instead:

toml
# hugo.toml
[markup.goldmark.renderer]
  unsafe = true

The form then survives, but Markdown still reads it. A tag that follows a blank line inside the form gets wrapped in a <p>, so the <label> for the message and the <button> each end up in their own paragraph. The shortcode gives you exactly the HTML you wrote, so prefer it.

Keep the form ID in hugo.toml ​

If the form appears on more than one page, or you might change it, keep the ID in one place:

toml
# hugo.toml
[params]
  bootformId = "{form_id}"

Move the form into a partial, layouts/partials/contact-form.html, and read the ID from the site params:

html
<form action="https://f.bootform.com/{{ site.Params.bootformId }}" method="POST">
  <label for="email">Your email</label>
  <input id="email" name="email" type="email" required>

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

  <input type="text" name="honeypot" style="position:absolute;left:-9999px" tabindex="-1" autocomplete="off">

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

A layout, such as a footer or a contact page template, includes the partial with this line. Replace the whole content of layouts/shortcodes/contact-form.html with the same line, and your content files keep working with one copy of the form:

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

While the value is still the placeholder, the built action shows %7bform_id%7d. Hugo escapes the braces because they sit in a URL. A real UUID has no braces and comes out unchanged.

A thank-you page ​

By default, a successful submission shows the visitor BootForm's short "Thanks" page. To send them to a page of your own instead, add a _redirect field with the full URL. Hugo's absURL function builds it from baseURL. Put this line inside the form in the partial:

html
<input type="hidden" name="_redirect" value="{{ "thanks/" | absURL }}">

and create the page it points at, content/thanks.md:

markdown
---
title: Thanks
---

Thanks, your message is on its way. We'll reply within a day.

Write the path without a leading slash. absURL treats a path that starts with a slash as relative to the host only, and drops the rest of baseURL. That matters on GitHub Pages, where a project site (anything but yourname.github.io itself) is served from a subpath. baseURL has to include it:

toml
# hugo.toml
baseURL = "https://yourname.github.io/your-repo-name/"

With that setting, "thanks/" becomes https://yourname.github.io/your-repo-name/thanks/, and "/thanks/" becomes https://yourname.github.io/thanks/, which is a 404. On your own domain, set baseURL to it, for example https://example.com/. The redirect has to point at the same site as the form, or at one of the form's allowed origins. BootForm ignores any other address and shows its own "Thanks" page.

Sending without leaving the page ​

To submit in the background and show a message in place, add the script from the Vanilla JS guide's AJAX section to the partial. It sends Accept: application/json and gets 200 {"ok":true} back. Leave _redirect out in that case; it only applies to a classic form post.

File uploads and the moderated feed ​

Both work on a Hugo site exactly as in plain HTML: see Vanilla JS, file upload and Vanilla JS, moderated content feed. A file upload needs the form claimed first.

Common problems ​

The page shows only the words "Message" and "Send" where the form should be. Hugo removed the form's HTML. The form is written in a Markdown file, or the shortcode is called with percent signs. Call the shortcode with angle brackets, as in the first example.

The built form's action ends in f.bootform.com/, with no ID. The template didn't find bootformId. Hugo gives no warning for a missing param. Check that the key sits under [params] in hugo.toml and is spelled the same in the template. Upper and lower case don't matter.

After sending, the visitor lands on a 404. The _redirect URL is wrong. Open the built page's source and check the value of the _redirect field. If the repository name is missing, remove the leading slash from the path you pass to absURL. If the host is not your site's, baseURL is missing or wrong in hugo.toml. Hugo does not warn about either.

The _redirect value starts with http://localhost:1313/. You are looking at a page served by hugo server, which replaces baseURL with its own address. Run hugo and check the file in public/ instead.

You sent a test message but no email arrived. The form isn't claimed yet. Nothing is delivered until it is; claim it and the messages sent so far are delivered. Held messages are kept for 48 hours.