How to Add ZIP Code Restrictions in Gravity Forms

Want to restrict form submissions to a specific area? Here's how we helped a client block submissions from ZIP codes outside their service zone using a custom validation method in Gravity Forms.

đźš« The Problem: Unwanted Submissions from Outside Service Areas

The client’s WooCommerce site was getting flooded with form entries from users outside their target ZIP code list—wasting valuable time and resources.

They wanted a simple, automatic way to stop this and only allow form submissions from approved ZIP codes.

🔍 What We Found

  • Gravity Forms doesn’t support this natively. There's no built-in ZIP validation.
  • A custom solution was required using a predefined ZIP list and a validation hook.
  • Initially, the client wanted this for one form, but later expanded it to cover all forms site-wide.

đź›  Implementation Steps

Step 1: Create a ZIP Code List

We converted the client’s list of 209 valid ZIP codes into a PHP array:

php

CopyEdit

$allowed_zips = ['20105', '20109', '20110', '20111', '20112', ...];

Step 2: Add Custom Validation Hook

We used a Gravity Forms filter to check the ZIP code field before submission:

php

CopyEdit

add_filter('gform_field_validation_4_9', 'custom_zip_validation', 10, 4);

function custom_zip_validation($result, $value, $form, $field) {
   $allowed_zips = [...]; // your ZIP list
   if (!in_array($value, $allowed_zips)) {
       $result['is_valid'] = false;
       $result['message'] = 'Sorry, we do not service your area.';
   }
   return $result;
}

(4 = Form ID, 9 = ZIP Code Field ID)

Step 3: Resolve Other Errors

While testing, we encountered unrelated JavaScript issues that were not tied to the ZIP logic. Once confirmed, we pushed the code live without risk.

Step 4: Make It Global

Later, we upgraded the logic to work across all forms by checking for any field labeled "ZIP Code" dynamically—so no need to edit each form individually.

🚀 Results That Matter

  • The site now automatically blocks ZIP codes outside the service area.
  • Lead quality and team productivity have both improved.
  • The setup is easy to update or expand as needed.

đź’ˇ Want to Build Smarter Forms?

Need advanced validations, field controls, or multi-form logic? We’ll help you get the most out of Gravity Forms and your WordPress stack.

‍

Need help improving your WordPress forms or custom workflows? We build clean, reliable, and growth-driven WordPress solutions—without breaking a sweat.

Let’s Talk

Other Resources Post

Fixing WordPress News Imports & Broken Links

Migrating legacy news posts to WordPress revealed messy data and broken links. With smart import tweaks and custom field logic, we transformed it into a clean, working archive.

Fix Missing UTM Tracking in GA4 & GTM

If your UTM tags show in URLs but not in GA4 reports, you're not alone. At Integriti Studio, we solved a real case where missing campaign data in GTM had a surprisingly simple fix.

Migrate WordPress—retain SEO.

Migrating your WordPress site doesn’t have to risk SEO—done right, it preserves rankings, traffic, and user experience while boosting performance, security, and reliability through
smart tools, and best practices.

Powered by Creativity,
Fueled by Caffeine.

Get Started