# Gravity Forms Zip Code Validation \[RESOLVED\]

**URL:** https://community.gravityforms.com/t/gravity-forms-zip-code-validation-resolved/1843
**Category:** Get Help
**Tags:** gform\_field\_validation, zip-code
**Created:** [May 13, 2019, 10:58pm UTC](https://community.gravityforms.com/t/gravity-forms-zip-code-validation-resolved/1843 "2019-05-13T22:58:18Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![dorys](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/dorys/32/747_2.png) [@dorys](https://community.gravityforms.com/u/dorys)
#### Post date: [May 13, 2019, 10:58pm UTC](https://community.gravityforms.com/t/gravity-forms-zip-code-validation-resolved/1843/1 "2019-05-13T22:58:18Z")

</div>

Hello,

I’m using the gform\_field\_validation to verify the applicant is in the correct zip code before moving on. I enter a valid zip code but I still get the invalid message.

Form can be seen [here](https://www.nextstepservicedogs.org/service-dog-application/).

This is my code

```auto
//GRAVITY FORMS ZIP CODE AUTHENTICATION

add_filter( 'gform_field_validation_15_193', 'custom_zip_validation', 10, 4 );
function custom_zip_validation( $result, $value, $form, $field ) {
    if ( $result['is_valid'] ) {
        $acceptable_zips = array(
        '91901',
		'91976',
		'92040',
		'92085',
		'92123',
		'92160',
		'91902',
		'91977',
		'83687',
		'83709',
		'83720',
		'83756',
		'83631',
		'83652',
		'83701',
		'83711',
		'83722',
		'83799',
		'83301',
		'83302',
		'83303',
		'83647'
        );
 
 
        if ( ! in_array( $zip_value, $acceptable_zips ) ) {
            $result['is_valid'] = false;
            $result['message'] = 'Zip validation failed. Unfortunately, we are not able to assist you. We currently serve the areas within an hour San Diego County, Santa Ana, California; and Boise, Idaho. Please visit the Assistance Dogs International (ADI) website for more information on service dog training. <a href="https://www.assistancedogsinternational.org/" target="_blank">https://www.assistancedogsinternational.org/</a>
';
        }
    }
 
    return $result;
}

```

---

<div class="post-metadata">

### Author: ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)
#### Post date: [May 14, 2019, 2:19am UTC](https://community.gravityforms.com/t/gravity-forms-zip-code-validation-resolved/1843/2 "2019-05-14T02:19:13Z")

</div>

You’re not assigning the information submitted in field 193 (the ZIP code) to `$zip_value` anywhere. So you are trying to see if `$zip_value` is in your `$acceptable_zips` array, but $zip\_value would be undefined at that point. With WP\_DEBUG or PHP warnings enabled you would see this notice.

You need something like this around line 31 (after `$acceptable_zips` is defined):

`$zip_value = rgar( $value, '193' );`

---

<div class="post-metadata">

### Author: ![dorys](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/dorys/32/747_2.png) [@dorys](https://community.gravityforms.com/u/dorys)
#### Post date: [May 14, 2019, 11:53am UTC](https://community.gravityforms.com/t/gravity-forms-zip-code-validation-resolved/1843/3 "2019-05-14T11:53:42Z")

</div>

Ah… I had removed that line from the original code because I know enough about php coding to get me into trouble. :-). I will add it back with the correct value. Thank you so much!!!

---

<div class="post-metadata">

### Author: ![dorys](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/dorys/32/747_2.png) [@dorys](https://community.gravityforms.com/u/dorys)
#### Post date: [May 14, 2019, 12:23pm UTC](https://community.gravityforms.com/t/gravity-forms-zip-code-validation-resolved/1843/4 "2019-05-14T12:23:57Z")

</div>

I added the line of code but it didn’t fix the issue. However, I did fix this by changing the field type from single line of text to address and showing only the zip code and then adding this line of code

```
	 $zip_value = rgar( $value, $field->id . '.5' );        

```

This solved the issue and it’s working now.

---

<div class="post-metadata">

### Author: ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)
#### Post date: [May 14, 2019, 4:43pm UTC](https://community.gravityforms.com/t/gravity-forms-zip-code-validation-resolved/1843/5 "2019-05-14T16:43:57Z")

</div>


