Using Gravity Forms for Age Verification: How to set up Age-based Validation

Often used for adult products (like alcohol) or concert tickets, age verification forms can prevent form submissions if the user’s age is below or above a specified threshold.

This article requires the GP Date Time Calculator perk.

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

View Plugin Buy Gravity Perks

Some forms need age-based restrictions attached to them. For example, an age verification form allowing entry to a site that advertises alcohol or cannabis can prevent submission if the user is below the minimum legal age.

In this tutorial, we’ll show you how to use GF Date Time Calculator to create a Gravity Forms age verification process to validate the user’s age and prevent submission based on that age. Let’s get started!

Getting Started

This tutorial will use GF Date Time Calculator to calculate the user’s age based on their birthdate. If the user’s age falls below a specified threshold, the submit button will be hidden and a validation message will display indicating why they can’t submit the form.


  1. Add a Date Field
  2. Add a Number Field and Calculate Age
  3. Add HTML Field and Set up Conditional Logic
  4. Apply Conditional Logic to The Submit Button

Step 1 – Add a Date Field

Start by adding a Date field to the form. In this field, we’ll capture the user’s birth date, so give it an appropriate name like “Date of Birth”.

add a date field to an age verification form in gravity forms

Step 2 – Add a Number Field and Calculate Age

Add a Number field to your form to calculate the user’s age. Enable calculation on the field and insert the merge tag for the “Date of Birth” field with the :age merge tag modifier to calculate age. Make sure to set the Date Calculation Unit to “Years”.

add a number field and calculate age on an age verification form

You should also set this field’s visibility to “Hidden” in the Advanced tab. It doesn’t need to be displayed to the user.

Step 3 – Add HTML Field and Set up Conditional Logic

With the age calculation handled, it’s time to create your validation message. Add an HTML field to the form and add your message. Enable Conditional Logic on the field and add rules to show the field if the user’s age is below (or above) your specified threshold.

using conditional logic for age validation

Note that we also have a rule so the field only shows if the “Date of Birth” field is not blank. This prevents the validation message from displaying before the user has entered a date.

Step 4 – Apply Conditional Logic to The Submit Button

With the validation message sorted, the next step is to prevent form submissions if the Age is below the threshold. To do this, activate Conditional Logic on the Submit button and set the rules to match this screenshot.

apply conditional logic to a submit button

This setting has the added benefit of preventing the Submit button from being active unless the user enters their Date of Birth.

Your age verification form is ready to go.

With everything set up, if a user enters a date of birth that is below our acceptable threshold, they’ll be shown a validation error and the Submit button will be hidden.

custom age validation message

Alternate age verification methods using Gravity Forms

Age-based validation can also be accomplished using GF Conditional Logic Dates.

Instead of using a Number field to calculate the user’s age, we’re going to do everything inside of the HTML and Submit button’s Conditional Logic. The magic lies in Conditional Logic Dates’ {today} merge tag. It lets you compare the user inputted date with a relative date from today. In the case of my form, we’re going to use {today:-18 years} to prevent submissions for anyone younger than 18. Here’s how it looks for my HTML field:

age based validation using conditional logic dates

Notice we’ve set the logic to “Date of Birth” is greater than {today:-18 years}. This will match any date value that is more recent than the relative date.

The Submit button Conditional Logic is set up similarly.

conditional logic submit button for age validation

More On Gravity Forms Validation

Gravity Forms Email Validation — validate an email in real time, as a form is being filled out — without having to click submit.

Gravity Forms Zip Code Validation — learn how to use conditional logic to validate a customer’s postal code before they submit their order.

Gravity Forms Advanced Phone Field — validate phone fields automatically this plugin for Gravity Forms. The plugin also includes automatic country code detection and phone meta capture!

Make Your Gravity Forms Validation Errors Mobile Friendly(er) — improve Gravity Forms validation errors for mobile users.

Require an Existing Value for Submission with Gravity Forms — ensure that a value entered in Form B has been previously submitted (or generated) on Form A. 

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.