Gravity Forms Email Validation: Check Emails Live Prior to Submission

Use this guide to learn how to validate a Gravity Forms Email field live before needing to click submit.

This article requires the GP Populate Anything perk.

Buy Gravity Perks to get this perk plus 47 other premium Gravity Forms plugins!

View Plugin Buy Gravity Perks

In this tutorial, we’re going to walk you through how to set up Gravity Forms email validation to check a user’s email live and prevent submissions if that email already exists.

gravity forms email validation

Extensible and powerful user management is a staple of WordPress. Not only are the built-in tools strong, the amount of plugins available to alter and supplement user management is incredible. Gravity Forms is a proud member of that group. With the User Registration Add-On, new users can easily sign up for a WordPress account using a Gravity Form. This opens the user registration process to a whole world of possibilities.

One of our users recently reached out asking for a way to check if an email already exists in their user registration form. Gravity Forms automatically validates the email and returns an error if the submitted email already has a user account associated with it, but this customer wanted to prevent those users from wasting their time filling out an unnecessary form.

Getting Started

This article will use Populate Anything to validate the entered email against existing users. If the email already exists, we will prevent the submission and display a link to the login page using Conditional Logic.

Steps

  1. Add an Email Field
  2. Add a Hidden Field and Populate Emails
  3. Add an HTML Field and Configure Conditional Logic
  4. Configure Submit Button Conditional Logic

Step 1 – Add an Email Field

User registration requires a valid email, so add one to your form if you haven’t already.

gravity forms add an email field

Step 2 – Add a Hidden Field and Populate Emails

Next, add a Hidden field to your form. In that Hidden field, we’re going to populate from the User object. Add a Filter Group and set the filter to match the “User Email” with your email field.

how to add a hidden field and populate emails in Gravity Forms

Leave the Value Template to the default of “User ID”.

setting up the value template in Gravity Forms

With these settings in place, if the user enters an Email that is connected to an existing user account, the user ID will populate. Otherwise, the field’s value will be blank.

Step 3 – Add an HTML Field and Configure Conditional Logic

Next, add an HTML field. In this field, insert a message and link to your login page.

Add an HTML field and configure conditional logic

Using Conditional Logic, we’re going to only display this field if the entered email exists. Set the conditional logic operator to “greater than” and set the value to 0. Since we’re populating the User ID into the “Email Exists” field, and no users have an ID of 0, we simply need to check if the populated User ID is greater than 0. If yes, the email is attached to an account, and we’ll show the HTML field.

enabling conditional logic in gravity forms

Looking to block certain emails entirely? Use Gravity Forms Blocklist to prevent submissions with specific keywords or IPs.

Step 3 – Configure Submit Button Conditional Logic

We’ll use the same Conditional Logic on the Submit button to prevent the user from being able to submit the form if the entered email exists. The only difference is that we’ll set it to Hide the button instead of show it.

configuring submit button conditional logic in gravity forms

That’s It

If you haven’t already set up the User Registration feed, go to the form’s Settings > User Registration and add a new Create User feed. You’ll be asked to map your fields to the new user’s profile. You can read more about setting things up in the docs.

With everything set up, your user registration form will prevent an existing user from attempting to register with an existing email. If they do, the Submit button is hidden and we present them with a login link.

gravity forms live email validation response message

More on Gravity Forms Validation

Comments

  1. Manuel Marchal Pancorbo
    Manuel Marchal Pancorbo January 10, 2024 at 7:53 am

    Hello.

    There is a problem, if in the E-mail field the option “Enable Email confirmation” is activated, the hidden field Email Exists gives as value the first existing user in the database, so this tutorial does not work with forms that have double email confirmation.

    Reply
    1. Scott Ryer
      Scott Ryer Staff January 10, 2024 at 1:49 pm

      Hi Manuel,

      This sounds like a configuration issue. I just tested this locally and couldn’t reproduce the issue. I’m going to follow up via email so we can troubleshoot this with you.

    1. Scott Ryer
      Scott Ryer Staff December 11, 2023 at 11:11 am

      Hi David,

      No, there isn’t a limit. While there is a limit to the number of results Populate Anything will return by default, it will search all users. In this case, only a single user is being returned.

  2. Jeremy Holden
    Jeremy Holden August 31, 2022 at 11:33 am

    Would it work to set this up with different User Registration feeds?

    So instead of Step 3 being a conditional display, adding 2 user registration feeds, one that is “create user” and one that is “update user”. Then using the same condition for those feeds.

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff August 31, 2022 at 11:58 am

      Hi Jeremy,

      By default, Gravity Forms doesn’t support having both the Update User Feed and Create User feed on the same form. You can however use this snippetof ours to override this and have both feeds on the same. You should then be able to set up the conditions on the feeds and see if it works for you.

      Best,

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.

Grab a bundle of free Gravity Forms plugins

Enter your email and receive our most popular free plugins and snippets, plus access to hundreds of others.

This field is for validation purposes and should be left unchanged.