# Help debugging call to gform\_field\_validation

**URL:** <https://community.gravityforms.com/t/help-debugging-call-to-gform-field-validation/4425>\
**Category:** Get Help\
**Tags:** gform\_field\_validation\
**Created:** [April 10, 2020, 6:46pm UTC](https://community.gravityforms.com/t/help-debugging-call-to-gform-field-validation/4425 "2020-04-10T18:46:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![user5e85fa28ed0e6034](https://avatars.discourse-cdn.com/v4/letter/u/d6d6ee/32.png) [@user5e85fa28ed0e6034](https://community.gravityforms.com/u/user5e85fa28ed0e6034)\
**Post date:** [April 10, 2020, 6:46pm UTC](https://community.gravityforms.com/t/help-debugging-call-to-gform-field-validation/4425/1 "2020-04-10T18:46:11Z")

</div>

Hi - I’m a long time developer but new to Gravity Forms and Wordpress. I can’t seem to get the filter gform\_field\_validation to fire. The bit of code is in the Functions.php file with the location of “wp-content/themes//resources/functions.php”.

To call the function that I created I’m using this:

```
//The following declaration targets field 1 in form 6
add_filter( 'gform_field_validation_6_1', 'your_function_name', 10, 4 );

```

That I copied from the documentation. Then changing it to use the values in my form (which is just generic code that I’m using to figure out how this works):

```
//Target field 24 in form 4
    add_filter( 'gform_field_validation_24_4', 'my_custom_validation', 10, 4 );
    function custom_validation( $result, $value, $form, $field ) {
        if ( $result['is_valid'] && intval( $value ) > 10 ) {
            $result['is_valid'] = false;
            $result['message'] = 'Please enter a value less than 10';
        }
        return $result;
    }

```

Also I can’t seem to figure out what the parameters 10 and 4 (sometimes I see 10 and 7) in the add\_ filter call. In the docs it states that those are the form and field object. I’ve tried it with 10, 4 - 10,7 - 4, 24 - and leaving it out all together.

Am I doing any of this correctly? Please help…

---

<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:** [April 10, 2020, 7:08pm UTC](https://community.gravityforms.com/t/help-debugging-call-to-gform-field-validation/4425/2 "2020-04-10T19:08:21Z")

</div>

10 is the priority at which the filter runs.

4 is the number of arguments the function accepts.

Neither of those need to be to changed. Those are WordPress conventions and not related to Gravity Forms:

[https://developer.wordpress.org/reference/functions/add\_filter/](https://developer.wordpress.org/reference/functions/add_filter/)

Now, what do you need help validating specifically? Let us know what your validation rules should be, and we’ll see if we can help. Thanks!

---

<div class="post-metadata">

**Author:** ![user5e85fa28ed0e6034](https://avatars.discourse-cdn.com/v4/letter/u/d6d6ee/32.png) [@user5e85fa28ed0e6034](https://community.gravityforms.com/u/user5e85fa28ed0e6034)\
**Post date:** [April 10, 2020, 8:34pm UTC](https://community.gravityforms.com/t/help-debugging-call-to-gform-field-validation/4425/3 "2020-04-10T20:34:16Z")

</div>

Thank you for the quick reply and the information!

I need to validate that the user picks a date from a date picker that’s at least one year in the past from the current date. Here’s my code:  
add\_filter( ‘gform\_field\_validation\_4\_24’,‘gt\_one\_year’ , 10, 4 );  
function gt\_one\_year( $result, $value, $form, $field ) {

```
	$userDate = rgpost('input_4_24');

	$userYear = $userDate[2];
	$currentYear = date('Y');  

	if ($currentYear == $userYear) {
		$result['is_valid'] = false;
               $result['message'] = "Date selected must be at least one year ago from today. Please correct.";
	}
   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:** [April 11, 2020, 2:04pm UTC](https://community.gravityforms.com/t/help-debugging-call-to-gform-field-validation/4425/4 "2020-04-11T14:04:19Z")

</div>

How about if you only allowed them to pick dates prior to one year ago? You could use this filter for that:

> **[gform\_datepicker\_options\_pre\_init - Gravity Forms Documentation](https://docs.gravityforms.com/gform_datepicker_options_pre_init/)**
>
> This filter can be used to modify the options used to initialize a fields datepicker.

If that’s an option, we can help with the validation code.

---

<div class="post-metadata">

**Author:** ![user5e85fa28ed0e6034](https://avatars.discourse-cdn.com/v4/letter/u/d6d6ee/32.png) [@user5e85fa28ed0e6034](https://community.gravityforms.com/u/user5e85fa28ed0e6034)\
**Post date:** [April 13, 2020, 1:20pm UTC](https://community.gravityforms.com/t/help-debugging-call-to-gform-field-validation/4425/5 "2020-04-13T13:20:55Z")

</div>

That would work great. I think that’s a better solution. Where do I place javascript in the form?

Just for my future understanding, do you see anything wrong with my php code?

I greatly appreciate your help!!

---

<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:** [April 13, 2020, 1:29pm UTC](https://community.gravityforms.com/t/help-debugging-call-to-gform-field-validation/4425/6 "2020-04-13T13:29:37Z")

</div>

To add the script to your form, you can add an HTML field to the form, and add the script there. Be sure you use the opening `<script>` and closing `</script>` tags.

As for your PHP code, I did not test it to know where it might not be working 🙂

---

<div class="post-metadata">

**Author:** ![richardw8k](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/richardw8k/32/2354_2.png) [@richardw8k](https://community.gravityforms.com/u/richardw8k)\
**Post date:** [January 5, 2022, 8:49am UTC](https://community.gravityforms.com/t/help-debugging-call-to-gform-field-validation/4425/7 "2022-01-05T08:49:10Z")

</div>


