Using Gravity Forms ‘gform_gf_field_create’ PHP filter

The gform_gf_field_create Gravity Forms PHP filter allows you to modify or replace the GF_Field object after it has been created.

Usage

add_filter('gform_gf_field_create', 'my_custom_function', 10, 2);

Parameters

  • $field (GF_Field): A GF_Field object of the type specified by the $properties['type'] or $properties['inputType'] properties.
  • $properties (array): An array of field properties that will be used to generate the GF_Field object.

More information

See Gravity Forms Docs: gform_gf_field_create

Examples

Create GF_Field object based on “type” property (rather than “inputType” property)

add_filter('gform_gf_field_create', 'my_custom_function', 10, 2);

function my_custom_function($field, $properties) {
    if ($field->type == 'myCustomFieldType') {
        $field = new GF_My_Custom_Field_Type($properties);
    }
    return $field;
}

This example demonstrates how to create a GF_Field object based on the “type” property, rather than the “inputType” property. When the field type is ‘myCustomFieldType’, a new instance of GF_My_Custom_Field_Type is created, and the original $field is replaced with the new instance.

Note: The provided code examples are fully functional, but you may need to adapt them to your specific use case.