DescriptionUsageParametersExamples1. Add new choicePlacementSource CodeSince
Description
The gform_field_map_choices filter can be used to override the choices available in the field map drop down.
Usage
1add_filter( 'gform_field_map_choices', 'your_function_name', 10, 4 );
Parameters
$fields array
The value and label properties for each choice.
$form_id integer
The ID of the form currently being configured.
$field_type null | array
Null or the field types to be included in the drop down.
$exclude_field_types null | array | string
Null or the field type(s) to be excluded from the drop down.
Examples
1. Add new choice
12345add_filter( 'gform_field_map_choices', function( $fields, $form_id, $field_type, $exclude_field_types ) { $fields[] = array( 'label' => 'The new choice', 'value' => 'new_choice' ); return $fields;}, 10, 4 );
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in Gravity_FormsGravity_FormsSettingsFieldsGeneric_Map::get_value_choices() in includes/settings/fields/class-generic-map.php.
Since
This filter was added in Gravity Forms 2.5.
Description
Allows the form object to be modified before the entry is updated by an add-on or the API.
Usage
The following would apply to all forms:
add_filter( 'gform_form_pre_update_entry', 'your_function_name', 10, 3 );
To target a specific form, append the form id to the hook name. (format: gform_form_pre_update_entry_FORMID)
add_filter( 'gform_form_pre_update_entry_1', 'your_function_name', 10, 3 );
Parameters
$form Form Object
The current form.
$entry Entry Object
The current entry.
$entry_id int
The ID of the current entry.
Example
The example below removes one of the form fields from the Form Object so that it is not updated with the entry data.
add_filter( 'gform_form_pre_update_entry', 'modify_form', 10, 3 );
function modify_form( $form, $entry, $entry_id ){
$fields = $form['fields'];
foreach ( $fields as $field ){
if ( $field['label'] == 'Test') {
continue;
}
$new_fields[] = $field;
}
$form['fields'] = $new_fields;
return $form;
}
Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms version 1.9.9.
Source Code
This filter is located in GFAPI::update_entry() in includes/api.php and
GF_Forms_Model_Legacy::update_entry() in includes/legacy/forms_model_legacy.php.
Description
Filter the current line being exported.
Usage
The following would apply to all forms:
add_filter( 'gform_export_line', 'append_lines_to_row', 10, 6 );
Parameters
$line string
The current line being exported.
$form array
The current form object.
$fields array
An array of field IDs to be exported.
$field_rows array
An array of List fields.
$entry array
The current entry.
$separator string
The separator.
Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms version 2.4.11.5.
Source Code
This filter is located in GFExport::prepare_forms_for_export() in export.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
Introduction
Use this filter to create a new field setting under the Advanced tab. Useful when implementing a new custom field type that requires custom settings.
Usage
1add_action( 'gform_field_advanced_settings', 'my_advanced_settings', 10, 2 );
Parameters
$position integer
Specifies the position that the settings will be displayed. For a list of all available positions, search form_detail.php for 「gform_field_advanced_settings」 or review the Advanced Field Settings article.
$form_id integer
The ID of the form from which the entry value was submitted.
Examples
This example creates a new Advanced setting on position 50 (right after the Admin Label setting), that specifies if the field data should be encrypted. This code sample works in Gravity Forms 2.4, 2.5 and later.
1234567891011121314151617181920212223242526272829303132333435add_action( 'gform_field_advanced_settings', 'my_advanced_settings', 10, 2 );function my_advanced_settings( $position, $form_id ) { //create settings on position 50 (right after Admin Label) if ( $position == 50 ) { ?>
EncryptionCheck this box to encrypt this field's data"; return $tooltips;}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in form_detail.php.
Description
This filter can be used to allow the csv entry export lines to be filtered just before they are saved to the temporary file.
Usage
add_filter( 'gform_export_lines', 'your_function_name' );
Parameters
$lines string
The lines to be included in the .csv export.
Example
This example fixes an issue on Excel for Mac.
add_filter( 'gform_export_lines', 'fix_csv_entry_export' );
function fix_csv_entry_export ( $lines ) {
return mb_convert_encoding( $lines, 'UTF-16LE', 'UTF-8' );
}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
$lines = apply_filters( 'gform_export_lines', $lines );
This filter is located in GFExport::start_export() in export.php.
Since
This filter was added in Gravity Forms 1.9.1.
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.
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.
Description
Allows the maximum execution time for exporting entries to be changed.
When the maximum execution time is reached, the export routine stops briefly and submits another AJAX request to continue exporting entries from the point it stopped.
Usage
add_filter( 'gform_export_max_execution_time', 'your_function_name, 10, 2 );
Parameters
$max_execution_time int
The number of seconds for which each request should run. Defaults to 20.
$form Form Object
The current form.
Example
add_filter( 'gform_export_max_execution_time', 'change_export_time', 10, 2 );
function change_export_time( $max_execution_time, $form ){
//change the execution time to 60 seconds
return 60;
}
Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms version 2.0.3.10.
Source Code
This filter is located in GFExport::start_export() in export.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 ) { ?>