Skip to content
Lazyform
Docs menu

Frameworks and builders

Hugo

Add a Lazyform contact form to a Hugo site as a partial or shortcode, with the access key in your site config.

Hugo builds static HTML, so a Lazyform form is just HTML in a template. Put the form in a partial, keep the key in your site config, and use a shortcode if you want to place the form inside Markdown content.

Before you start

Get an access key: type your email on the homepage for an instant key, or sign in and create a form. Replace YOUR_ACCESS_KEY with your key (it starts with lf_).

Add the key to your config

hugo.toml
[params.lazyform]
  accessKey = "YOUR_ACCESS_KEY"
  redirect = "https://example.com/thanks/"

The form partial

layouts/partials/contact-form.html
<form action="https://lazyform-api.xvelopers.com/submit" method="POST" class="lazyform">
  <input type="hidden" name="access_key" value="{{ site.Params.lazyform.accessKey }}">
  {{ with site.Params.lazyform.redirect }}
  <input type="hidden" name="redirect" value="{{ . }}">
  {{ end }}
  <input type="hidden" name="subject" value="New message from {{ site.Title }}">

  <label>Name <input type="text" name="name" required></label>
  <label>Email <input type="email" name="email" required></label>
  <label>Message <textarea name="message" rows="5" required></textarea></label>

  <input type="checkbox" name="botcheck" class="hidden" style="display:none">

  <button type="submit">Send</button>
  <p class="status" role="status"></p>
</form>

Use it in any layout with {{ partial "contact-form.html" . }}.

Use it inside Markdown

Partials can't be called from content files, so wrap it in a shortcode:

layouts/shortcodes/contact-form.html
{{ partial "contact-form.html" .Page }}

Then, in any Markdown page, write {{< contact-form >}} where you want the form.

Optional: submit without leaving the page

Add this script once, for example in layouts/partials/footer.html. It upgrades every .lazyform form to show an inline message. Without JavaScript, the form still posts normally.

layouts/partials/lazyform-script.html
<script>
  document.querySelectorAll('form.lazyform').forEach((form) => {
    const status = form.querySelector('.status');
    form.addEventListener('submit', async (event) => {
      event.preventDefault();
      status.textContent = 'Sending...';
      try {
        const response = await fetch(form.action, {
          method: 'POST',
          headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
          body: JSON.stringify(Object.fromEntries(new FormData(form))),
        });
        const result = await response.json();
        status.textContent = result.success
          ? 'Thanks! Your message has been sent.'
          : result.error?.message || 'Something went wrong.';
        if (result.success) form.reset();
      } catch {
        status.textContent = 'Network error. Please try again.';
      }
    });
  });
</script>

Tips

  • The key is safe to be public. It only allows submitting to your form. Turn on allowed websites in the form's settings to lock it to your domain.
  • Several forms. Create one form per purpose in the dashboard (each has its own key) and add more keys under params.lazyform.

Where to go next