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 individual
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.
👉 Talk to Integriti Studio today — Let’s improve how your forms work.
Let’s fix it