Gatsby Netlify Forms Examples Recaptcha v2

Netlify Status

Gatsby Starter Default + Netlify Forms Examples + reCAPTCHA v2

This starter contains Netlify forms examples and reCAPTCHA with the main Gatsby configuration files you might need to run your contact form page.

Below you will find instructions for each step.

πŸš€ Quick start

  1. Clone this repository

    Download ZIP or:

    git clone https://github.com/RafalMCichon/gatsby-netlify-form-examples.git

    or:

    Clone and deploy with a click

    Deploy to Netlify

  2. Installation

    Install dependencies.

    yarn

πŸ“„ Environment variables files

  1. Create two .env files at the top-level (root)
  2. .env.development
  3. .env.production

      .
      β”œβ”€β”€ node_modules
      β”œβ”€β”€ src
      β”œβ”€β”€ .env.development
      β”œβ”€β”€ .env.production
      β”œβ”€β”€ .gitattributes
      β”œβ”€β”€ .gitignore
      β”œβ”€β”€ .prettierignore
      β”œβ”€β”€ .prettierrc
      β”œβ”€β”€ gatsby-browser.js
      β”œβ”€β”€ gatsby-config.js
      β”œβ”€β”€ gatsby-node.js
      β”œβ”€β”€ gatsby-ssr.js
      β”œβ”€β”€ LICENSE
      β”œβ”€β”€ package.json
      β”œβ”€β”€ README.md
      └── yarn.lock

πŸ”‘ Create reCAPTCHA keys

  1. To create reCAPTCHA keys click here or copy the link: https://www.google.com/recaptcha/intro/v3.html
  2. Open Admin console

admin-console-button

  1. Click + button to create new key

    netlify-change-site-name

πŸ” Step by step Register a new site

  1. Label

    netlify-change-site-name

    your website domain or project name

  2. reCAPTCHA type

    netlify-change-site-name

    reCAPTCHA v2

  3. "I'm not a robot" tickbox (checkbox)
  4. Domains

    netlify-change-site-name

  5. your-domain
  6. site-name.netlify.com (for netlify test)
  7. localhost (for development)
  8. β˜‘οΈ Accept the reCAPTCHA Terms of Service (checkbox)

    netlify-change-site-name

  9. Submit

    netlify-change-site-name

    netlify-change-site-name

  10. COPY SITE KEY and paste in your .env files:

    GATSBY_SITE_RECAPTCHA_KEY = your_site_key
  11. COPY SECRET KEY and paste in your .env files:

    GATSBY_SITE_RECAPTCHA_SECRET = your_secret_key
  12. Go to analytics

βš›οΈ Start developing.

  1. Navigate into your new site’s directory and start it up:

    gatsby develop

πŸ”§ Netlify Settings for reCAPTCHA 2

  1. Add New site from Git and Deploy site
  2. Open Site settings and Change site name to your github project name

    netlify-change-site-name

    this name is needed in the reCAPTCHA Domains configuration

  3. Open Build & deploy / Environment / Edit variables Set the key and secret in your site’s build environment variables.

    gatsby-env-edit-variables

  4. Use GATSBY_SITE_RECAPTCHA_KEY to set your site key, and GATSBY_SITE_RECAPTCHA_SECRET to set the secret value provided by reCAPTCHA 2 - more details here.

    gatsby-env-forms

    remember to add a prefix **`GATABY`**_

    (unlike in netlify documentation)

  5. Open Deploys / Trigger deploys and Clear cache and deploy site

    netlify-trigger-deploys-clear-cache-and-deploy-site

πŸ“ Setup Netlify Form submissions

  1. Go to Forms and check if they are all visible there - if not make sure they have unique names.

    netlify-forms-active-forms

🧐 Tips

Netlify Recaptcha: If you’re using the:

<form data-netlify-recaptcha="true"></form>

element to add our recaptcha, you can only have one form using this. If you create multiple forms, receiving submissions will not work.

Test - first submissions

  1. Go to Site settings / Forms / Form notifications and Add notification.
  2. Choose Email notification.

    netlify-email-notification

  3. Add Email to notify - your-email
  4. Choose Form

    netlify-email-notification-form

  5. And Save !

    we are ready to test if everything works

Netlify Form

β€” Netlify.
#header h1 a {
  display: block;
  width: 300px;
  height: 80px;
}
<div hidden>
  <label>
    Don’t fill this out if you're human:
    <input name="bot-field" onChange={this.handleChange} />
  </label>
</div>
Published 2 Jan 2020

Product Manager Β· Front-end Web Developer at Inventive Software LLC
Rafal M Cichon on Twitter