🎉 Celebrate with 10% OFF on All Products! Use Code: GFEX10 Or Buy Any 2+ Items for 30% OFF with Code: GFEX30!
Guides & Tutorials October 22, 2026

How to Restrict a Gravity Forms Form by Visitor Country (Without Breaking Page Caching)

GravityExtra
How to Restrict a Gravity Forms Form by Visitor Country (Without Breaking Page Caching)

Some forms should not be open to the whole world. A sign-up for a service you only deliver in three countries, a quote request that is only valid in one state, a privacy request form for people in the European Union, a competition that the law allows only in certain places, a support form that you do not want to keep receiving from regions where you have no customers. Gravity Forms can validate fields, route notifications and run feeds, but it has no idea where the visitor is. This guide shows how to restrict a form by the visitor’s country with the Gravity Forms Geo Restriction Premium Add-on, and how to do it so that it keeps working behind a cache and cannot be skipped.

Why the check has to happen on the server

The simplest way to limit a form is a little script that hides it when the browser says the visitor is somewhere else. That is a courtesy, not a rule. A script can be switched off, a cached page can be served to anyone, and a form can be posted to your site by a program that never loads the page. If you want a real restriction, the decision has to be made again when the form is sent, on your server, from information the visitor cannot edit.

That is how this add-on is built. The page shows what each visitor should see, and then the submission is checked once more, on every page of a multi page form, including the save and continue later button. A visitor from a closed country gets your message and nothing is stored, nothing is e-mailed and nothing is sent to your CRM.

Step 1: choose where the country comes from

A country is worked out from the visitor’s address, and there are four reasonable places to get it. The add-on tries them from the most trusted to the least trusted and takes the first that answers.

  • Cloudflare. If your site is behind Cloudflare, every request carries the visitor country in a header. The add-on believes it only when the connection really comes from a Cloudflare address, because anyone who finds your server address could otherwise send a header saying they are in the right country. You can also choose to believe the header always, if your server only takes Cloudflare traffic.
  • CloudFront or a header of your own. Amazon CloudFront and several hosts can pass the country on in a header. Switch it on only if you set that up.
  • A database on your own server. The free MaxMind GeoLite2 database is looked up locally, so no address leaves your site. You create a free MaxMind account and a licence key, enter them once, and the add-on downloads the database and refreshes it every week.
  • An IP service. If you prefer, use ipinfo.io or ip-api.com with your own key. Answers are kept for a day.
The Geo Restriction settings screen: Cloudflare, CloudFront, own header, the local GeoLite2 database with its status and the IP service options
Where the country comes from, in the order of trust, with the status of the local database.

The settings screen shows the state of the local database: what is installed, when it was built, when it was last checked and when the next update is due. If a download fails, for example because a key was mistyped, the old database stays in place and the screen tells you why.

Step 2: set the rule on the form

Open the form and choose Settings, then Geo Restriction. Turn the restriction on and decide between an allow list and a block list. With an allow list, only the countries you list can use the form. With a block list, everyone can except the countries you list.

The Geo Restriction form settings: restrict by country, allow or block, countries, regions, groups, what a restricted visitor gets, the message and the entry option
The rule of one form: who is allowed or blocked, what they get, and the message.

Write countries as two-letter codes, such as US, CA, GB or DE. If you need to be more precise, add regions or states in the form US-CA or CA-ON, which needs the larger City database or an IP service. There are also two groups: all European Union member states and everything outside them. The add-on keeps its own list of the 27 member states, which means the United Kingdom, Switzerland and Norway count as outside.

Then choose what a restricted visitor gets. The form can disappear and be replaced by your message, it can stay visible with the send buttons disabled and your message above it, or the visitor can be sent to another page, such as a page that explains where you do operate. Finally decide what happens when the country cannot be found, which can happen with private networks, some VPNs and missing data. Most sites let the visitor through, and a strict form can refuse instead.

Step 3: see what a visitor sees

You do not need to travel, or to find a VPN, to check your rule. Add a country code to the address of any page that holds the form, such as the page address followed by ?gfgeo_country=DE, and you see and can send the form as a visitor from Germany. Only administrators can do this, and a line above the form tells you that test mode is on and what that visitor gets. For everyone else the parameter is ignored. Without it, administrators see every form as usual, so a rule never locks you out.

A Gravity Forms form replaced by a message that the sign-up is only open in the United States, Canada and Germany, naming the visitor country
A visitor from outside the allowed countries sees your message instead of the form.

Step 4: pages that are cached

Many sites run a page cache, through a plugin, the host or a CDN. A cached page is built once and handed to everybody, so a restriction applied while the page was built would apply to the first visitor only. For those sites, switch on the page caching setting. The page then looks the same for everyone, and a very small request after the page has loaded asks the site what this visitor should get. The form is removed, locked or replaced by a redirect at that moment, and the answer is never cached. Because the real check happens when the form is sent, a visitor who bypasses the script still cannot submit.

Use the country inside your forms

The country is more than a gate. It is also useful data. Four merge tags are available in confirmations, notifications and anywhere else that accepts merge tags: the country code, the country name, the region and whether the visitor is in the European Union. A notification can say that a request came from Germany, and a confirmation can mention it.

Each entry of a restricted form also saves the country, the region and how the location was found. The entry screen has a Visitor location box, and the country is available as a column and as a filter in the entries list, so you can see where your leads come from.

For logic inside the form, add a Hidden field with the default value {visitor_country}. Conditional logic can then show a VAT number field only to visitors from Germany, or a state field only to visitors from the United States. The hidden field is filled in again on the server when the form is sent, so editing it in the browser changes nothing.

Privacy and the law

Working out a country from an address is processing of personal data in many places, so it is worth being careful. The add-on does not store the visitor address. It uses it for one lookup per request, and adds only the country, and the region where known, to the entry. With the local database nothing is sent to anyone. With an IP service, the address goes to that service, and your privacy policy should say so. The list of refused submissions is switched off by default, and keeps addresses only if you switch that on as well. The add-on adds a suggested paragraph to the WordPress privacy policy guide.

Remember also that the country found from an address is an estimate. Visitors on a VPN or a mobile network can appear in the wrong place, and the free database is less precise than paid ones. Use a restriction to focus a form on the people you serve, and take legal advice before relying on it for anything that the law requires.

Checklist before you go live

  1. Choose the sources and, for the local database, press the download button and check the status line.
  2. Set the rule on each form and write a clear message that says what the visitor can do instead.
  3. Test a few countries with the test parameter, including one that is allowed and one that is not.
  4. Switch on page caching if your pages are cached, and test from a private window.
  5. Decide what happens when the country is unknown.
  6. Add the data source line and a note about the lookup to your privacy page.

Frequently asked questions

Does this slow my site down?

Looking an address up in the local database takes a fraction of a millisecond and the database is read from disk without loading it into memory. Answers from an IP service are kept for a day.

What if my site is behind Cloudflare and someone finds my server address?

Leave the Cloudflare setting on its default, which believes the header only for connections from Cloudflare addresses. A forged header on any other connection is ignored.

Can I limit only a region, such as one state?

Yes. Add the region in the form US-CA, and use the City database or an IP service that gives regions.

Which Gravity Forms versions does it support?

Gravity Forms 2.9 and newer. It is tested with Gravity Forms 3.1.2 on PHP 8.3 and Gravity Forms 2.9.8 on PHP 7.4.

Is the free database allowed for this?

The GeoLite2 databases are free to use with a MaxMind account under the terms you accept there. The add-on downloads them with your own key and shows the attribution line that MaxMind asks for.

Get started

The Gravity Forms Geo Restriction Premium Add-on gives every form its own country rule, a check on every submission, and the visitor location in your merge tags, entries and conditional logic. See the features, the price and the setup guide on the add-on page.

See the Geo Restriction add-on

0
0
Your Cart
Your cart is emptyReturn to Shop
🔥 FREQUENTLY BOUGHT TOGETHER
Complete Combo & Save 40%!
ITEM IN YOUR CART
Gravity Forms Klaviyo Add-on
$39.00/yr
+
🎁 RECOMMENDED ADD-ON SAVE 40% OFF
Original Price: $39.00/yr
Bundle Special Price: $23.40/yr