Skip to content
Lazyform
Docs menu

Frameworks and builders

Jekyll

Add a Lazyform contact form to a Jekyll or GitHub Pages site as a reusable include, with the key in _config.yml.

Jekyll and GitHub Pages serve static files only, so forms need a backend somewhere else. Lazyform is that backend: add an include with the form and use it on any page.

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

_config.yml
lazyform:
  access_key: YOUR_ACCESS_KEY
  redirect: https://example.com/thanks/

Restart jekyll serve after editing _config.yml; it isn't reloaded automatically.

The form include

_includes/contact-form.html
<form action="https://lazyform-api.xvelopers.com/submit" method="POST" class="lazyform">
  <input type="hidden" name="access_key" value="{{ site.lazyform.access_key }}">
  {% if site.lazyform.redirect %}
  <input type="hidden" name="redirect" value="{{ site.lazyform.redirect }}">
  {% endif %}
  <input type="hidden" name="subject" value="{{ include.subject | default: 'New message from my website' }}">

  <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 page or layout:

contact.md
---
layout: page
title: Contact
---

Have a question? Send us a message.

{% include contact-form.html subject="New contact message" %}

Optional: submit without leaving the page

Add this once to your layout, for example before </body> in _layouts/default.html:

_includes/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>

Then add {% include lazyform-script.html %} to the layout.

Tips

  • GitHub Pages. This works on GitHub Pages without plugins, since the browser posts straight to Lazyform.
  • 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.

Where to go next