Using Gravity Forms ‘gform_field_filter_from_post’ PHP filter

The gform_field_filter_from_post is a Gravity Forms PHP filter that enables you to modify the filter settings for form fields retrieved from $_POST.

Usage

A generic example to apply this filter to all forms:

add_filter('gform_field_filter_from_post', 'your_function_name', 10, 3);

Parameters

  • $field_filter (array) – The form field, entry properties, and entry meta filter settings.
  • $form (Form Object) – The form object.
  • $field (Field Object) – The field object.

More information

See Gravity Forms Docs: gform_field_filter_from_post

Place the code in the functions.php file of the active theme, a custom functions plugin, or a custom add-on.

Examples

Change Filter Settings for Specific Field

Modify the filter settings for a specific field in a form with the ID 1:

function modify_field_filter_settings($field_filter, $form, $field) {
    if ($form['id'] == 1 && $field['id'] == 2) {
        // your custom code here to modify the $field_filter
    }
    return $field_filter;
}
add_filter('gform_field_filter_from_post', 'modify_field_filter_settings', 10, 3);

Add Custom Filter for All Fields

Add a custom filter for all fields in a form with the ID 1:

function add_custom_filter($field_filter, $form, $field) {
    if ($form['id'] == 1) {
        // your custom code here to add a custom filter to $field_filter
    }
    return $field_filter;
}
add_filter('gform_field_filter_from_post', 'add_custom_filter', 10, 3);

Remove Specific Filter for a Field

Remove a specific filter for a field in a form with the ID 1:

function remove_specific_filter($field_filter, $form, $field) {
    if ($form['id'] == 1 && $field['id'] == 2) {
        // your custom code here to remove a specific filter from $field_filter
    }
    return $field_filter;
}
add_filter('gform_field_filter_from_post', 'remove_specific_filter', 10, 3);

Modify Filter Settings Based on Field Type

Modify the filter settings based on the field type in all forms:

function modify_filter_settings_by_type($field_filter, $form, $field) {
    if ($field['type'] == 'text') {
        // your custom code here to modify the $field_filter for text fields
    }
    return $field_filter;
}
add_filter('gform_field_filter_from_post', 'modify_filter_settings_by_type', 10, 3);

Add Filter for Fields with a Specific CSS Class

Add a custom filter for fields with a specific CSS class in all forms:

function add_filter_for_css_class($field_filter, $form, $field) {
    if (strpos($field['cssClass'], 'my-custom-class') !== false) {
        // your custom code here to add a custom filter to $field_filter
    }
    return $field_filter;
}
add_filter('gform_field_filter_from_post', 'add_filter_for_css_class', 10, 3);