Skip to content
Lazyform

Contact form for Gatsby

Add a contact form page to your Gatsby site with no functions or plugins. Submissions are delivered to your email, Telegram, Slack or Google Sheets.

Free plan: 250 submissions a month, forever.

Why a form backend for Gatsby

Gatsby builds your site into static HTML, which is why it's fast and cheap to host. It also means there's nothing running to receive a form. Gatsby Functions can fill the gap on some hosts, but then you're writing email code and spam checks yourself.

Lazyform keeps your site fully static. Add one page, point it at our endpoint, and every message is checked for spam, stored and delivered.

A working contact form

Create a new page and replace YOUR_ACCESS_KEY with your key from /login.

src/pages/contact.js
import * as React from 'react'

export default function ContactPage() {
  const [result, setResult] = React.useState(null)

  const onSubmit = async (event) => {
    event.preventDefault()
    setResult({ sending: true })

    const res = await fetch('https://lazyform-api.xvelopers.com/submit', {
      method: 'POST',
      headers: { Accept: 'application/json' },
      body: new FormData(event.target),
    })
    setResult(await res.json())
  }

  if (result?.success) {
    return <main><p>Thanks! We'll be in touch soon.</p></main>
  }

  return (
    <main>
      <h1>Contact us</h1>
      <form onSubmit={onSubmit}>
        <input type="hidden" name="access_key" value="YOUR_ACCESS_KEY" />
        <input type="text" name="name" placeholder="Name" required />
        <input type="email" name="email" placeholder="Email" required />
        <textarea name="message" placeholder="Message" required />
        <input type="checkbox" name="botcheck" className="hidden" style={{ display: 'none' }} />
        <button type="submit" disabled={result?.sending}>Send</button>
        {result?.error && <p role="alert">{result.error.message}</p>}
      </form>
    </main>
  )
}

export const Head = () => <title>Contact us</title>

Gatsby turns src/pages/contact.js into the /contact/ route automatically, and the Head export sets the page title.

Get submissions where you want them

Every submission is emailed to you. Add Telegram, Slack, Discord or WhatsApp alerts, or copy submissions into Google Sheets, Notion or Airtable. See all integrations.

Full guide

The Gatsby guide covers environment variables, a reusable form component, file uploads and captcha.

Questions

Do I need Gatsby Functions or a plugin?

No. The page posts to Lazyform from the browser, so it works on a plain static Gatsby build with no functions, plugins or GraphQL.

Does it matter where I host my Gatsby site?

No. The form works the same on Netlify, Vercel, Cloudflare Pages, GitHub Pages, S3 or any other static host.

Can I keep the key in an environment variable?

Yes. Gatsby exposes variables that start with GATSBY_ to the browser, so GATSBY_LAZYFORM_KEY works. The key is public by design and cannot read submissions.