🎉 Celebrate with 10% OFF on All Products! Use Code: GFEX10 Or Buy Any 2+ Items for 30% OFF with Code: GFEX30!

Gravity Forms Geo Restriction Premium Add-on Setup Guide

Updated 12 min read Gravity Forms Integrations A–Z
On this page
  1. Video walkthrough
  2. What you need
  3. Install and activate
  4. Where the country comes from
  5. 1. Cloudflare
  6. 2. CloudFront and your own header
  7. 3. The local database (MaxMind GeoLite2)
  8. 4. An IP service (optional)
  9. Behind a proxy
  10. Set the rule of a form
  11. What a restricted visitor sees
  12. The check on every submission
  13. Page caching
  14. Administrators and test mode
  15. Use the country inside the form
  16. For developers
  17. Privacy and GDPR
  18. Good to know
  19. Troubleshooting
  20. Questions
  21. Do I need a paid MaxMind account?
  22. Does it work with Cloudflare page rules or caching plugins?
  23. Can a visitor get around it?

Video walkthrough

Gravity Forms Geo Restriction: Allow or Block a Form by Visitor Country, Region or EU
Video tutorial: Gravity Forms Geo Restriction Watch on YouTube

The Gravity Forms Geo Restriction Premium Add-on lets you decide, form by form, which visitors may use a Gravity Forms form, based on the country they are in. A form can be limited to a list of countries, closed to a list of countries, limited to the European Union or kept away from it, and narrowed down to a region or state. Visitors who are not allowed see your message instead of the form, see the form but cannot send it, or are sent to another page.

The check happens twice: when the form is shown, and again on the server when the form is sent. That second check is the one that counts, because it cannot be skipped by a cached page, by saving the page and posting it somewhere else, or by a script that talks to the form directly.

What you need

  • WordPress 6.5 or newer and PHP 7.4 or newer.
  • Gravity Forms 2.9 or newer. The add-on is tested with Gravity Forms 3.1.2 on PHP 8.3 and Gravity Forms 2.9.8 on PHP 7.4.
  • An active license key. Without an active license the add-on does nothing: forms are shown and sent as if it was not installed.
  • At least one way to learn the country of a visitor: a header from Cloudflare or Amazon CloudFront, a free MaxMind account for the local database, or your own key for an IP service. The sections below explain each one.

If Gravity Forms is missing or older than 2.9, the add-on shows a notice in the WordPress admin and does nothing else.

Install and activate

  1. Install and activate the add-on like any plugin, after Gravity Forms.
  2. Open Forms → Settings → Geo Restriction and enter your license key.
  3. In the same screen, choose where the country comes from (next section).
  4. Open a form, go to Settings → Geo Restriction, turn on Restrict this form by country and set the rule.

Where the country comes from

The add-on tries the sources in a fixed order, from the one it trusts most to the one it trusts least, and uses the first one that gives a country. You switch on only what your site really uses.

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.

1. Cloudflare

Cloudflare adds the visitor country to every request in the CF-IPCountry header when IP Geolocation is on for your zone, which it is by default. A header is only text, though: anyone who can reach your server directly can send one with any country in it. So the add-on offers three settings. Off ignores the header. On, believe the header only when the request comes from a Cloudflare address checks the address of the connection against the published Cloudflare ranges first, and ignores the header on any other request. On, always believe the header is for servers that only accept Cloudflare traffic, or that already replace the connection address with the visitor address; you choose it yourself, knowing that. If your site is not behind Cloudflare, leave it off and a forged header changes nothing.

When the verified request also carries the Cloudflare region header, the region code is used for region rules. Without it, a region rule needs the City database or an IP service.

2. CloudFront and your own header

Amazon CloudFront can pass the CloudFront-Viewer-Country header to your server through an origin request policy. Tick CloudFront only if you set that up. Some hosts and other CDNs set a header of their own with the two-letter country; type its name in Header of my own CDN or host and the add-on reads it. These two are believed as they are, because there is no short list of addresses to check them against, so use them only when your server cannot be reached around the CDN.

3. The local database (MaxMind GeoLite2)

With the local database the country is looked up on your own server, and no visitor address is sent anywhere. You need a free MaxMind account: create it on the MaxMind site, accept the GeoLite licence there, and create a licence key. Then enter the account ID and the licence key, choose the database and save. Press the download button once, and the add-on downloads the database with your own key. After that WordPress downloads a fresh copy every week by itself.

  • GeoLite2 Country is small and gives the country. GeoLite2 City is larger and also gives the region or state, which region rules need.
  • The database is saved in the uploads folder, in a folder with a random name that is closed to web visitors, and the file is checked before it replaces the old one. A failed download never removes a working database.
  • The licence key is sent to MaxMind only. The file itself is fetched without it.
  • The settings screen shows what is installed, when it was built, when it was last checked and the result, and when the next update is due. A Delete the database button removes it.
  • The database is read by a reader that is part of the add-on, so no PHP extension is needed.

MaxMind asks for an attribution line when you use GeoLite2: This product includes GeoLite2 data created by MaxMind, available from https://www.maxmind.com. It is shown on the settings screen, and you can add it to your privacy page or footer. The GeoLite end user licence agreement, which you accept in your own MaxMind account, applies to the database.

4. An IP service (optional)

If you prefer a service, choose ipinfo.io or ip-api.com Pro and enter your own key. The add-on asks the service only when the sources above gave no country, keeps each answer for a day so a busy form does not ask again for every visitor, and treats a failed request as an unknown country. The visitor address is sent to the service you choose, so tell your visitors in your privacy policy.

Behind a proxy

Normally the visitor address is the address of the connection. If a proxy that you control puts the visitor address in the X-Forwarded-For header, switch on Visitor address behind a proxy. Leave it off otherwise, because anyone can send that header.

Set the rule of a form

Open the form, then Settings → Geo Restriction.

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.
  • Restrict this form by country: the on and off switch. A form with the switch off is never touched.
  • Rule: only visitors from the places below can use this form (an allow list), or visitors from the places below cannot use this form (a block list).
  • Countries: two-letter ISO codes, such as US, CA, GB, DE, separated by commas, spaces or lines.
  • Regions or states (optional): a country code, a hyphen and the region code or name, one per line, for example US-CA, CA-ON or GB-England. The comparison ignores capitals, spaces and accents.
  • Groups (optional): all European Union member states, and all countries outside the European Union. The add-on has its own list of the 27 member states, so the United Kingdom, Switzerland and Norway are outside it.
  • What a restricted visitor gets: hide the form and show a message, show the form but refuse to send it, or send the visitor to another page.
  • Message: shown instead of the form, above it, and when a submission is refused. {visitor_country_name} works in it.
  • When the country cannot be found: let the visitor use the form (the default), or treat the visitor as restricted. Private networks, some VPNs and a missing database give no country.
  • Entries: save the visitor country in each entry of this form.

In an allow list, a visitor is allowed when the country, the region or a group matches. In a block list, a visitor is blocked when any of them matches.

What a restricted visitor sees

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.
  • Hide the form: the form is not in the page at all. Only your message is.
  • Show the form but refuse to send it: the form is shown with your message above it, the send buttons are inactive, and the server refuses the submission with the same message if it is posted anyway.
  • Redirect: when the page holds the form as a shortcode or as a block, the visitor gets a redirect before any of the page is sent. Forms placed in other ways get a message with a link and a script that moves the visitor on.

The check on every submission

Whatever the page showed, a submission from a restricted visitor is refused on the server, on every page of a multi page form, and when the visitor presses Save and continue later, so no draft is stored either. A form posted straight to your site, a form scraped from a saved page and a submission through the Gravity Forms API get the same answer. No entry is created, no notification is sent and no feed runs.

Page caching

If a page cache or a CDN stores your pages, the first visitor decides what everybody gets, unless the add-on is told. Switch on Page caching on the settings screen. The page then looks the same for every visitor and holds the form; a very small request after the page has loaded asks your site what this visitor gets, and the form is removed, locked or replaced by a redirect. A form that is waiting for the answer is not shown, and a visitor whose browser cannot run scripts still meets the server check on submission. The request is never cached by the browser.

Without the page caching setting the add-on marks pages with such a form as not cacheable, using the constant and the headers that most cache plugins respect, but a host or CDN that ignores them can still keep a copy. If in doubt, switch the setting on.

Administrators and test mode

  • Administrators: users who can edit forms always see and send every form (setting on by default). Switch it off to see exactly what a visitor sees.
  • Test mode: an administrator adds ?gfgeo_country=DE to a page address and sees, and can send, the form as a visitor from Germany. Add &gfgeo_region=Bavaria for a region. A line above the form says that test mode is on and what the visitor would get. Nobody else can use it: for a visitor, or a user who cannot edit forms, the parameter is ignored.

Use the country inside the form

The visitor location is available as merge tags, as entry data and as a hidden field value.

  • Merge tags: {visitor_country} (the code), {visitor_country_name}, {visitor_region} and {visitor_eu} (yes or no). They work in confirmations, notifications and anywhere else that takes merge tags. For an entry they use the country saved with the entry.
  • Entry data: the country, the region and how the location was found are saved with each entry of a form that has a rule (or of every form if you tick the option). The entry screen shows a Visitor location box, and the country can be shown as a column and used as a filter in the entries list.
  • Hidden field: add a Hidden field and give it the default value {visitor_country}, or tick Allow field to be populated dynamically and use the parameter name gfgeo_country (also gfgeo_country_name, gfgeo_region and gfgeo_eu). Conditional logic can then show or hide other fields by country, for example a VAT number field only for a German visitor.

The hidden field is filled in again on the server when the form is sent, before the conditional logic is evaluated, so a visitor who edits the value in the browser gains nothing.

For developers

  • gfgeo_get_visitor() returns the visitor of the current request: country, region_code, region_name, is_eu and source.
  • gfgeo_form_allows_visitor( $form_id ) tells whether the current visitor may use the form.
  • Filters: gfgeo_visitor, gfgeo_rule, gfgeo_is_restricted, gfgeo_client_ip, gfgeo_cloudflare_ranges, gfgeo_eu_countries, gfgeo_cache_mode, gfgeo_bypass_capability and gfgeo_server_vars.

Privacy and GDPR

  • The visitor address is used for one lookup per request and is not saved by the add-on. Gravity Forms itself saves the address in each entry unless you switched that off in its own settings.
  • Only the country, and the region when it is known, are added to entries.
  • The list of refused submissions is off by default. When you switch it on, it keeps the last 100 refusals with the time, the form and the country. The address is added to that list only if you also switch on the second option. The number of refused submissions per form is always counted, without any personal data.
  • The add-on adds a suggested paragraph to the WordPress privacy policy guide, and the settings screen explains which source sends what where. If you use an IP service, the visitor address goes to that service.
  • Deleting the plugin removes its settings, counters, saved lookups and the downloaded database. Entries and the saved country in entries stay.

Good to know

  • A country found from an address is an estimate. Visitors on a VPN, a mobile network or a company network may appear in another country. The free database is less exact than paid databases, and it is least exact for small regions and cities.
  • Geo Restriction decides who can use a form. It does not hide the page, and it is not legal advice on whether you may offer something in a country.
  • An entry added by code with the Gravity Forms API, or imported, is not a visitor submission and is not checked.

Troubleshooting

  • Nothing is restricted: check that the license is active, that the form has the switch on, and use test mode to see the result for a country. On the settings screen, Check an address shows the country that the database or service gives for an address.
  • Everybody is allowed: the country was not found. Look at When the country cannot be found, check the database status and that your site shows the visitor address and not that of a proxy.
  • The wrong country: if the site is behind a proxy or CDN, the address of the connection is the proxy. Use the CDN header, or the proxy setting.
  • The database does not download: the status line shows the reason, such as wrong account ID or key, a blocked connection, or an archive that could not be unpacked. The old database stays in use.

Questions

Do I need a paid MaxMind account?

No. The add-on uses the free GeoLite2 databases, and a free account and licence key from MaxMind are enough.

Does it work with Cloudflare page rules or caching plugins?

Yes. Switch on the page caching setting. The server check on submission works in every case.

Can a visitor get around it?

A visitor who really appears to be in another country, for example through a VPN, is treated as being there. A forged country header changes nothing unless you told the add-on to believe that header.

Still need help?

Our support team answers tickets every day, usually within a few hours.

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