How to Validate VAT Numbers in Real Time in Gravity Forms

Connect Gravity Forms to a VAT validation API to check numbers instantly as users type and catch invalid entries before submission.

  1. What You’ll Need
  2. 1 — Create a Connection Profile
    1. Create the Endpoint
  3. 2 — Build VAT Validation Form
    1. Add Form Fields
    2. Connect GP Populate Anything to GC API Alchemist
    3. Add Feedback Messages
    4. Show/Hide Submit Button
  4. 3 — Prevent Tampering
  5. 4 — Test Drive
  6. Wrapping Up

VAT Numbers keep you compliant and your invoices accurate. But let’s be real, manually validating them is tedious. One invalid VAT number can mean compliance issues and extra admin work you don’t need.

But, what if you could validate VAT numbers instantly, catching errors before they happen?

Today, we’re going to brew a solution using GC API Alchemist, which bridges Gravity Forms with any API—including VAT validation services. We’ll pair it with GP Populate Anything which handles the real-time validation. It sends the VAT number to the API, gets the result, and updates the form instantly. 

Together? They create a vigilant VAT validator. 🦸

This article requires the Gravity Connect API Alchemist plugin.

Buy Gravity Connect to get this plus other premium Gravity Forms plugins!

View Plugin Buy Now

What You’ll Need

  1. GC API Alchemist: connects the form to a VAT validation API.
  2. GP Populate Anything: pings the API after the users type and stores the result.
  3. Conditional Logic: shows/hides the submit button based on validity.
  4. A magical snippet: prevents tampering with the validation result.
  5. A free account at EU VAT API.

But wait, what’s an API (Application Programming Interface)? Think of them as messengers that let two apps talk to each other. In our case, it’s how Gravity Forms talks to a VAT validation service.

You can learn more by checking out our beginner-friendly guide that breaks down APIs in plain English.

1 — Create a Connection Profile

First, we’ll connect GC API Alchemist to the VAT validation API. We’re using the EU VAT API for this guide.

  1. Open your Spellbook › activate GC API Alchemist.
  2. Navigate to FormsAPI Connections.
  3. Click Add New API Connection to create the profile.
  4. In General:
    • Base URL: https://euvatapi.com/api/v1/
    • Description: EU VAT Number Validation
Screenshot showing the General tab of the GC API Alchemist Connection Profile with Base URL and Description fields filled in.
  1. In Authentication:
    • Type: API Key
    • Head to https://euvatapi.com/ › copy your API keypaste.
    • Key Location: Query Parameter
    • Key Name: access_key
Screenshot showing the Authentication tab of the GC API Alchemist Connection Profile with Type, Key, Location, and Name fields filled in.
  1. Click Publish.

Create the Endpoint

But what is an endpoint? Think of it as a specific question you’re asking the API. You send info (VAT number) and specify what answer you want back (whether it’s valid).

  1. In the new connection profile › click Create Endpoint.
  2. In Configuration:
    • Name: VAT Validator
    • API Endpoint: validate — this creates https://euvatapi.com/api/v1/validate
    • Click Next.
Screenshot showing the Endpoint configuration window of the GC API Alchemist with basic information filled in.
  1. In Data & Property Mapping › skip for now › click Next.
  2. In Query Parameters & Filters:
    • Click Add Parameter.
    • Parameter Name: vat_number — this is data the API will use to validate against.
    • Click Next.
Screenshot showing the Endpoint Query Parameters window of the GC API Alchemist with a 'vat_number' parameter added.
  1. Data & Property Mapping (Round 2):
    • You’ll see the new vat_number parameter.
    • Enter a test number: FR40303265045
    • The API auto-tests and shows the full response data.
    • Leave property mapping as-is › click Next.
Screenshot showing the Endpoint Data & Property Mapping window of the GC API Alchemist with the parameters filled in.
  1. Query Parameters & Filters (Round 2) › click Next.
  2. In Cache Settings: Leave caching enabled — saves API calls and tokens.
  3. Click Create Endpoint.

Alright! You’ve now taught GC API Alchemist the language it needs to speak with the VAT API.

2 — Build VAT Validation Form

Let’s create the form where users enter the VAT numbers and where GP Populate Anything validates them in real-time.

Add Form Fields

  1. Open your Spellbook › activate GP Populate Anything.
  2. Create a new form (or edit an existing one).
  3. Add a Single Line Text field:
    • Label: VAT Number
  4. Add another Single Line Text field (this will store the result):
    • Label: Is VAT Valid?
    • Go to Advanced › Visibility › set to hidden.
    • Check Allow field to be populated dynamically.
The form editor shows two single line text fields.

Connect GP Populate Anything to GC API Alchemist

  1. Still in the Is VAT Valid? field › enable Populate value dynamically.
  2. Configure Population:
    • Type: API Alchemist
    • Connection Profile: EU VAT API
    • Endpoint: VAT Validator
    • Add Filter Group › set to vat_number is VAT Number field.
    • Value Templates: Set to valid (this pulls the validation result from the API)

Add Feedback Messages

We can control the feedback messages using conditional logic.

  1. Add an HTML field:
    • Content: VAT number is valid ✅
    • Enable Conditional Logic: Show if All match: Is VAT valid? is 1 (1 means true)
The form editor with an HTML field selected, with the Conditional logic flyout open.
  1. Add another HTML field:
    • Content: VAT number is invalid ❌
    • Enable Conditional Logic: Show if All match: Is VAT valid is not 1
    • Add another condition: VAT Number is not [leave empty] — this prevents showing the error when field is blank.
The form editor with an HTML field selected, with the Conditional logic flyout open.

Show/Hide Submit Button

Let’s hide that submit button until the VAT number checks out.

  1. Click the Submit button to edit.
  2. Enable Conditional Logic
  3. Show if All match: Is VAT valid? is 1
The form editor with the submit button selected, with the Conditional logic flyout open.

3 — Prevent Tampering

A tech-savvy user could open the browser’s tools and manually change the value in the hidden field. To prevent this, we’ll use the force repopulation snippet that’ll force the form to double-check with the API one last time right before the form is submitted.

  1. Go to PluginsAdd New › search for Code Snippets › install and activate.
  2. Navigate to Snippets Add New.
  3. Copy the force repopulation snippet code.
  4. Paste the code into the new snippet.
  5. Add a title › Force Repopulation
  6. Save and Activate.

Now, when someone submits the form, the VAT number will be checked one more time on the server. If someone tries to cheat by changing the hidden field, the system will catch it and check again. 👮

4 — Test Drive

Let’s make sure everything works.

  1. Preview the form.
  2. Enter an invalid VAT number — try GB999999999
    • Invalid message appears
    • Submit button stays hidden
  3. Enter a valid VAT number — try FR40303265045
    • Valid message appears
    • Submit button shows up
A user submits an invalid VAT number and receives an invalid message, then deletes it and replaces it with a valid VAT number and receives a valid message.

If all works as expected, you’re done!

Pro Tip

Now that you’ve validated the VAT number, you might want to take it a step further and automatically calculate those VAT/tax amounts right in your form. Check out how you can calculate tax and VAT in Gravity Forms to round out your invoicing setup.

Wrapping Up

Let’s do a quick recap of what we just built.

  • Connected Gravity Forms to a live VAT validation API.
  • Validated user input VAT numbers in real-time thanks to GP Populate Anything.
  • Secured the form against invalid submissions.

And VAT’s a wrap! Give yourself a pat on the back. 🙌

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.


This field is for validation purposes and should be left unchanged.
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.