Description
This filter can be used to modify the markup, the li, used for the field container.
Important: Do not return li
tags when legacy markup is disabled. Removing attributes from the container tag can break features of the form editor, such as ajax saving.
Usage
The base filter which would run for all forms and all fields would be used like so:
add_filter( 'gform_field_container', 'your_function_name', 10, 6 );
To target a specific form append the form id to the hook name. (format: gform_field_container_FORMID)
add_filter( 'gform_field_container_10', 'your_function_name', 10, 6 );
To target a specific field append both the form id and the field id to the hook name. (format: gform_field_container_FORMID_FIELDID)
add_filter( 'gform_field_container_10_3', 'your_function_name', 10, 6 );
Parameters
- $field_container string
The field container markup. The placeholder {FIELD_CONTENT} indicates where the markup for the field content should be located.
-
$field Field Object
The field currently being processed.
-
$form Form Object
The Form currently being processed.
-
$css_class string
The CSS classes to be assigned to the li element.
-
$style string
An empty string as of 1.9.4.4. Was previously used to hold the conditional logic display style.
-
$field_content string
The markup for the field content (label, description, and inputs etc) which will replace the {FIELD_CONTENT} placeholder.
Example
add_filter( 'gform_field_container', 'my_field_container', 10, 6 );
function my_field_container( $field_container, $field, $form, $css_class, $style, $field_content ) {
return str_replace( ' class="', ' class="some-custom-class ', $field_container );
}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
gf_apply_filters( 'gform_field_container', array( $form['id'], $field->id ), $field_container, $field, $form, $css_class, $style, $field_content );
This filter is located in GFFormDisplay::get_field() in form_display.php
Since
This filter was added in Gravity Forms 1.8.9.