Description
The 「gform_field_groups_form_editor」 filter in Gravity Forms is used to modify the field groups in the Form Editor before fields are added, allowing control over what displays.
Usage
add_filter( 'gform_field_groups_form_editor', 'your_function_name', 10, 1 );
Parameters
$field_groups array
The field groups, including group name, label and fields.
Example
This example changes the label for Standard Fields to Testing.
add_filter( 'gform_field_groups_form_editor', 'change_title', 10, 1 );
function change_title( $field_groups ){
foreach ( $field_groups as &$group ){
if ( $group['name'] == 'standard_fields' ){
$group['label'] = 'Testing';
}
}
return $field_groups;
}
Placement
Your code snippet should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFFormDetail::get_field_groups() in gravityforms/form_detail.php.
DescriptionUsageParametersExamples1. Add a custom payment status2. Add an operator to a specific fieldPlacementSinceSource Code
Description
The 「gform_field_filters」 filter in Gravity Forms enables the filter settings to be overridden for the form fields, entry properties, and entry meta.
Usage
1add_filter( 'gform_field_filters', 'your_function_name', 10, 2 );
Parameters
$field_filters array
The form field, entry properties, and entry meta filter settings.
$form Form Object
The form object.
Examples
1. Add a custom payment status
123456789101112131415161718192021add_filter( 'gform_field_filters', 'update_filters', 10, 2 );function update_filters( $field_filters, $form ){ foreach ( $field_filters as &$filter ){ if ( $filter['key'] == 'payment_status' ){ //add custom payment status $values = $filter['values']; $status_exists = false; foreach( $values as &$value ){ if ( $value['text'] == 'Test Status' ){ $status_exists = true; } } if ( ! $status_exists ){ //add status array_push( $values, array( 'text' => 'Test Status', 'value' => 'Test Status' ) ); $filter['values'] = $values; } } } return $field_filters;}
2. Add an operator to a specific field
12345678910add_filter( 'gform_field_filters', function ( $field_filters, $form ) { foreach ( $field_filters as $filter ) { if ( rgar( $filter, 'key' ) == '2' ) { $filter['operators'][] = 'isnot'; break; } } return $field_filters;}, 10, 2 );
Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms 2.3.1.16.
Source Code
This filter is located in GFCommon::get_field_filter_settings() in common.php
Description
This filter fires after a form field is deleted.
Usage
12345678
Parameters
event Event Object
Default JS event object.
form Form Object
The current form object.
fieldId integer
The current field ID.
Examples
This example uses the gform_admin_pre_render filter to load the hook. A message is displayed if the form id is 44 and field id 1 is deleted.
1234567891011121314add_action( 'gform_admin_pre_render', 'pre_render_function' );function pre_render_function( $form ) { ?>
Description
This filter can be used to dynamically add/remove CSS classes to a field.
Usage
add_filter( 'gform_field_css_class', 'custom_class', 10, 3 );
You can also specify this per form by adding the form id after the hook name.
add_filter( 'gform_field_css_class_6', 'custom_class', 10, 3 );
Parameters
$classes string
The CSS classes to be filtered, separated by empty spaces, (i.e. 「gfield custom_class」).
$field Field Object
Current field.
$form Form Object
Current form.
Examples
This example dynamically adds a custom class to all text fields:
add_filter( 'gform_field_css_class', 'custom_class', 10, 3 );
function custom_class( $classes, $field, $form ) {
if ( $field->type == 'text' ) {
$classes .= ' custom_textfield_class';
}
return $classes;
}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFFormDisplay::get_field() in form_display.php.
DescriptionUsageParametersExamples1. New field type based on field class name2. Add Autocomplete Attribute3. Remove field from Entry Detail4. Display Section field description on Entry Detail5. Change a field to be readonly6. Add HTML tags to some text in your field7. Add a custom CSS classPlacementSource Code
Description
This filter is executed before creating the field』s content, allowing users to completely modify the way the field is rendered. It can also be used to create custom field types.
It is similar to gform_field_input, but provides more flexibility.
Usage
add_filter( 'gform_field_content', 'my_custom_function', 10, 5 );
// apply to a specific form
add_filter( 'gform_field_content_123', 'my_custom_function', 10, 5 );
// apply to a specific form and field
add_filter( 'gform_field_content_123_6', 'my_custom_function', 10, 5 );
Parameters
$field_content string
The field content to be filtered.
$field Field Object
The field that this input tag applies to.
$value string
The default/initial value that the field should be pre-populated with.
$entry_id integer
When executed from the entry detail screen, $lead_id will be populated with the Entry ID. Otherwise, it will be 0.
$form_id integer
The current Form ID.
Examples
1. New field type based on field class name
This example creates a sub-section field, replacing fields with a subsection custom CSS class.
add_filter( 'gform_field_content', 'subsection_field', 10, 5 );
function subsection_field( $content, $field, $value, $lead_id, $form_id ) {
//The edit and delete links need to be added to the content (if desired), when using this hook
$admin_buttons = IS_ADMIN ? $delete_field_link . " " . __( 'Edit', 'gravityforms' ) . "" : "";
$content = "{$admin_buttons}
" . $field->label . "
";
}
}
return $content;
}
2. Add Autocomplete Attribute
This example shows how you can edit the input markup and add extra attributes
add_filter( 'gform_field_content', function ( $field_content, $field ) {
if ( $field->type == 'email' ) {
return str_replace( 'type=', "autocomplete='email' type=", $field_content );
}
return $field_content;
}, 10, 2 );
This example shows how you can edit the input markup and add extra attributes to the Credit Card field inputs.
add_filter( 'gform_field_content', function ( $field_content, $field ) {
if ( $field->type == 'creditcard' ) {
$field_content = str_replace( ".1' id", ".1' autocomplete='cc-number' id", $field_content );
$field_content = str_replace( "_2_month'", "_2_month' autocomplete='cc-exp-month'", $field_content );
$field_content = str_replace( "_2_year'", "_2_year' autocomplete='cc-exp-year'", $field_content );
$field_content = str_replace( ".3' id", ".3' autocomplete='cc-csc' id", $field_content );
$field_content = str_replace( ".5' id", ".5' autocomplete='cc-name' id", $field_content );
}
return $field_content;
}, 10, 2 );
This example shows how you can edit the input markup to add the autocomplete=』off』 for the Address field Country drop down.
add_filter( 'gform_field_content', function ( $field_content, $field ) {
if ( $field->type == 'address' ) {
return str_replace( "name='input_3.6'", "autocomplete='off' name='input_3.6'", $field_content );
}
return $field_content;
}, 10, 2 );
See the following Google article for more detail on the autocomplete attribute.
3. Remove field from Entry Detail
This example shows how you can prevent a field (id 2) being displayed on the entry detail page.
add_filter( 'gform_field_content', function ( $field_content, $field, $value ) {
// Change 2 to the id number of your field.
if ( $field->id == 2 ) {
if ( $field->is_entry_detail_edit() ) {
$value = esc_attr( $value );
$name = 'input_' . esc_attr( $field->id );
5. Change a field to be readonly
add_filter( 'gform_field_content', function( $field_content, $field ) {
if ( $field->id == 1 || $field->id == 51 ) {
return str_replace( 'type=', "readonly='readonly' type=", $field_content );
}
return $field_content;
}, 10, 2 );
6. Add HTML tags to some text in your field
This example shows how to wrap a word in a field between HTML tags, an use case for this would be to add custom formatting to the text in your field label. In this case we』re also using the form id in the filter name to limit its action to a single form.
add_filter( 'gform_field_content_45', function( $field_content, $field ) {
if ( $field->id == 1 ) {
return str_replace( 'Best', "Best", $field_content );
}
return $field_content;
}, 10, 2 );
7. Add a custom CSS class
This example shows how to add a custom CSS class ( your_class ) to a field with id 17 on a form with id 758.
add_filter( 'gform_field_content', function ( $content, $field, $value, $lead_id, $form_id ) {
GFCommon::log_debug( __METHOD__ . '(): modified field content ' . $content );
// Change 758 and 17 to your form id and field id respectively.
if ( $form_id == 758 && $field->id == 17 ) {
return str_replace( "class='", "class='your_class ", $content );
}
return $content;
}, 10, 5 );
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in the following methods:
GFEntryDetail::lead_detail_edit() in entry_detail.php
GFEntryDetail::lead_detail_grid() in entry_detail.php
GFFormDisplay::get_field_content() in form_display.php
Description
This filter can be used to modify the markup, the li, used for the field container.
Usage
The base filter which would run for all forms and all fields would be used like so:
1add_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)
1add_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)
1add_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.
';}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
1gf_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.
Description
This filter is executed when creating the checkbox or radio button items. It can be used to manipulate the item』s string before it gets added to the checkbox or radio button list.
Usage
1add_filter( 'gform_field_choices', 'form_submit_button', 10, 2 );
Parameters
$choices string
The string containing the choices to be filtered i.e.
1$field Field Object
The current field.
Examples
This example demonstrates how to allow HTML characters on checkbox and radio items.
12345add_filter( 'gform_field_choices', 'decode_specialchars', 10, 2 );function decode_specialchars( $choices, $field ) { $choices = htmlspecialchars_decode( $choices ); return $choices;}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in the following methods:
GF_Field_Checkbox::get_checkbox_choices() in includes/fields/class-gf-field-checkbox.php
GF_Field_Radio::get_radio_choices() in includes/fields/class-gf-field-radio.php
Description
The 「gform_field_choice_selected_type_form_editor」 JavaScript filter in Gravity Forms allows the 「input type」 for choices (checkbox, radio) to be overridden. This hook is used when custom types have been created and will only be needed with such a special case.
Usage
12345gform.addFilter( 'gform_field_choice_selected_type_form_editor', function( type, field ) { // do stuff return type;} );
Parameters
type string
The choice selected input type. Defaults to checkbox for checkbox type fields or radio for other field types.
field Field Object
The current field.
Example
12345678910111213141516add_action( 'gform_admin_pre_render', 'set_choice' );function set_choice( $form ) { ?>
DescriptionUsageParametersExamples1. Add Custom Attribute2. Include Price for Product Fields3. Remove choice based on date4. Add CSS class to Multiselect choice5. Add inline list headingsPlacementSource Code
Description
This filter allows you to override the default choice markup used when rendering radio button, checkbox and drop down type fields.
Usage
To apply the filter to all radio, checkbox and drop down type fields on all forms you can do this:
To target a specific field on a specific form append the form id and the field id to the hook name. (format: gform_field_choice_markup_pre_render_FORMID_FIELDID)
This example shows how you can update the option markup to include the choice price for the drop down type Product field.
add_filter( 'gform_field_choice_markup_pre_render', function ( $choice_markup, $choice, $field, $value ) {
if ( $field->type == 'product' ) {
$new_string = sprintf( '>%s - %s<', $choice['text'], GFCommon::to_money( $choice['price'] ) );
return str_replace( ">{$choice['text']}<", $new_string, $choice_markup );
}
return $choice_markup;
}, 10, 4 );
3. Remove choice based on date
This example shows how you can remove a choice from a specific field if the specified date has passed.
add_filter( 'gform_field_choice_markup_pre_render_10_5', function ( $choice_markup, $choice ) {
if ( rgar( $choice, 'value' ) == 'test' && time() >= strtotime( '2019-10-03' ) ) {
return '';
}
return $choice_markup;
}, 10, 2 );
4. Add CSS class to Multiselect choice
This example shows how you can add a CSS class to a Multiselect field choice labeled as 「Second Choice」.
// Change 543 and 2 to your form id and field id respectively.
add_filter( 'gform_field_choice_markup_pre_render_543_2', function ( $choice_markup, $choice, $field, $value ) {
// Change Second Choice to the label of your choice.
if ( $field->get_input_type() == 'multiselect' && rgar( $choice, 'text' ) == 'Second Choice' ) {
// Change my_class to the CSS class name you want to use.
return str_replace( "value=", "class='my_class' value=", $choice_markup );
}
return $choice_markup;
}, 10, 4 );
5. Add inline list headings
This example shows how you can replace a choice with an inline heading, by prepending your option label with ###.
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in the following methods:
GFCommon::get_select_choices() in common.php – since 1.9.11.10GF_Field_Checkbox::get_checkbox_choices() in includes/fields/class-gf-field-checkbox.php – since 1.9.6GF_Field_Radio::get_radio_choices() in includes/fields/class-gf-field-radio.php – since 1.9.6
Introduction
Used to add additional options to the field appearance settings.
Note: Be sure to check for the first parameter in your function. This action fires multiple times.
Usage
1add_action( 'gform_field_appearance_settings', 'my_function', 10, 2 );
Parameters
$position integer
The position where the action is currently firing. Each time the action is called, it will return a different position. For a list of all available positions, search form_detail.php for 「gform_field_appearance_settings」 or review the Appearance Field Settings article.
$form_id integer
The ID of the form that the action is being run on.
Examples
123456function my_function($placement, $form_id) { if( $placement == 50 ) { //Insert new appearance field HTML here }}add_action( 'gform_field_appearance_settings', 'my_function', 10, 2 );
Source Code
This action hook is located in form_detail.php.