gform_file_upload_markup

gform_file_upload_markup

DescriptionUsageJavaScript VersionParametersExamplesChange delete buttonAccess temporary filenamePlacementSource CodePHP VersionParametersExamplePlacementSource Code

Description
The 「gform_file_upload_markup」 filter can be used to modify the HTML for the multi-file upload 「preview」.
Usage
The gform_file_upload_markup filter has both a JavaScript version and a PHP version. Both versions should be used.
The JavaScript version modifies the HTML the first time the uploaded file preview displays.
gform.addFilter( 'gform_file_upload_markup', function( html, file, up, strings, imagesUrl, response ) {
// do stuff

return html;
} );

The PHP version changes the uploaded file preview HTML on a multi-page form when you click Previous/Next after a file has been uploaded.
add_filter( 'gform_file_upload_markup', function( $file_upload_markup, $file_info, $form_id, $field_id ) {
// do stuff

return $result;
}, 10, 4 );

JavaScript Version

Parameters

html string
The current html for the field.

file Javascript Object
Details about the file uploaded.

up Javascript Object
The FileUpload object.

strings Javascript Object
Strings used for upload messages.

imagesUrl string
The URL to the images folder.

response Javascript Object
The response from GFAsyncUpload. Since version 2.4.22.3.
{
"status": "ok",
"data": {
"temp_filename": "randomly-generated-temp-filename-here.png",
"uploaded_filename": "image.png"
}
}

Examples
Change delete button
This example shows how to change the delete button that is next to the uploaded file.
gform.addFilter('gform_file_upload_markup', function (html, file, up, strings, imagesUrl) {
var formId = up.settings.multipart_params.form_id,
fieldId = up.settings.multipart_params.field_id;
html = '' + file.name + " ";

return html;
});

Access temporary filename
This example shows how you can access the temporary file name of the uploaded file with Gravity Forms 2.4.22.3 and greater.
gform.addFilter( 'gform_file_upload_markup', function( html, file, up, strings, imagesUrl, response ) {
var temp_name = rgars( response, 'data/temp_filename' );
// Do something with the temp_name.

return html;
} );

Placement
Your code snippet can be placed in an HTML field on your form or in the theme』s custom JavaScript file that loads on the form』s page.
Source Code
This filter is located in js/gravityforms.js.
PHP Version

Parameters

$file_upload_markup string
The current html for the field.

$file_info array
Details about the file uploaded.

$form_id integer
Form ID.

$field_id integer
Field ID.

Example
This example shows how to change the delete button that is next to the uploaded file.
add_filter( 'gform_file_upload_markup', 'change_upload_markup', 10, 4 );

function change_upload_markup( $file_upload_markup, $file_info, $form_id, $field_id ) {
return '' . esc_html( $file_info['uploaded_filename'] ) . " ";
}

Placement
Your code snippet should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GF_Field_FileUpload::get_field_input() in gravityforms/includes/fields/class-gf-field-fileupload.php.

gform_form_export_filename

gform_form_export_filename

DescriptionUsageParametersExamplePlacementSinceSource Code

Description
Allows the form export filename to be changed.
Note: Do not include a file extension. The extension 「.json」 is added.
Usage
add_filter( 'gform_form_export_filename', 'your_function_name', 10, 1 );

Parameters

$filename string
The new filename to use for the export file.

Example
add_filter( 'gform_form_export_filename', function( $filename ) {
return 'new-filename-without-extension';
} );

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.3.4.
Source Code
This filter is located in GFExport::export_forms() in export.php.

gform_field_type_title

gform_field_type_title

DescriptionUsageParametersExamplesPlacementSource Code

Description
When adding a new field type, use this filter to assign a title to the new type.
Usage
1add_filter( 'gform_field_type_title','assign_title', 10, 2 );
Parameters

$title string
Title to be filtered. Defaults to the field type.

$field_type string
Field type.

Examples
This example assigns a title to a new custom field type.
12345678add_filter( 'gform_field_type_title', 'assign_title', 10, 2 );function assign_title( $title, $field_type ) {    if ( $field_type == 'map' ) {        return 'Map';    } else {        return $title;    }}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFCommon::get_field_type_title() in common.php

gform_footer_init_scripts_filter

gform_footer_init_scripts_filter

DescriptionUsageParametersExamplePlacementSinceSource Code

Description
Allows the scripts that fire in the footer to be modified.
Note: The gform_init_scripts_footer must be set to true so scripts are initialized in the footer of the site instead of the page body.
Usage
The following would apply to all forms:
add_filter( 'gform_footer_init_scripts_filter', 'your_function_name', 10, 3 );

To target a specific form, append the form id to the hook name. (format: gform_footer_init_scripts_filter_FORMID)
add_filter( 'gform_footer_init_scripts_filter_1', 'your_function_name', 10, 3 );

Parameters

$form_string string
A string of the scripts used in the footer.

$form Form Object
The current form.

$current_page int
The ID of the current page.

Example
add_filter( 'gform_footer_init_scripts_filter', 'filter_footer', 10, 3 );
function filter_footer( $form_string, $form, $current_page ){
$form_string .= "";
return $form_string;
}

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.8.4.
Source Code
This filter is located in GFFormDisplay::footer_init_scripts() in form_display.php.

gform_field_input

gform_field_input

DescriptionUsageParametersExamplesPlacementSource Code

Description
This filter is executed before creating the field』s input tag, allowing users to modify the field』s input tag. It can also be used to create custom field types.
Usage
12// apply to all formsadd_filter( 'gform_field_input', 'my_custom_function', 10, 5 );
12// apply to a specific formadd_filter( 'gform_field_input_123', 'my_custom_function', 10, 5 );
12// apply to a specific form and fieldadd_filter( 'gform_field_input_123_6', 'my_custom_function', 10, 5 );
Parameters

$input string
The input tag string to be filtered. Will be passed to the hook an empty string value. Return an empty string to bypass the filtering, or change its value to specify a new input tag.

$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
This example creates a google map field, replacing fields with a google_map custom CSS class. This example is not intended to be fully functional, but to demonstrate what can be accomplished with this hook. In combination with some other Administration hooks, this hook can be used to create completely custom field types, such as a Map field type.
1234567add_filter( 'gform_field_input', 'map_input', 10, 5 );function map_input( $input, $field, $value, $lead_id, $form_id ) {    if ( $field->cssClass == 'google_map' ) {        $input = '

';    }    return $input;}
This example creates a hidden field on the form using a specific name. Please note: if you use a custom name attribute then Gravity Forms won』t know how to access the value so it will not be saved during form submission.
12345678add_filter( 'gform_field_input', 'tracker', 10, 5 );function tracker( $input, $field, $value, $lead_id, $form_id ) {    // because this will fire for every form/field, only do it when it is the specific form and field    if ( $form_id == 23 && $field->id == 11 ) {        $input = '';    }    return $input;}
This example displays an image from a post on the form by replacing the tag with the tag returned from WordPress』 wp_get_attachment_image function. You need to know the attachment id.
12345678add_filter( 'gform_field_input', 'display_attachment', 10, 5 );function display_attachment( $input, $field, $value, $lead_id, $form_id ) {    //because this will fire for every form/field, only do it when it is the specific form and field    if ( $form_id == 23 && $field->id == 12 ) {        $input = wp_get_attachment_image( 114 );    }    return $input;}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFCommon::get_field_input() in common.php

gform_form_pre_results

gform_form_pre_results

DescriptionUsageParametersExamplesPlacementSource Code

Description
Use this filter to modify the Form object prior to calculating the results in the results admin page. The results page is currently only used by add-ons that implement the Add-On Framework.
Usage
1add_filter( 'gform_form_pre_results', 'your_function_name' );
You can also target a specific form by adding the form id after the hook name. (format: gform_form_pre_results_FORMID)
1add_filter( 'gform_form_pre_results_10', 'your_function_name' );

Parameters

$form array
The form object.

Examples
This example adds the field id to the field labels.
1234567add_filter( 'gform_form_pre_results', 'modify_results_fields' );function modify_results_fields( $form ) {    foreach ( $form['fields'] as &$field ) {        $field['label'] .= sprintf( " (Field ID: %d)", $field['id'] );    }    return $form;}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
1apply_filters( "gform_form_pre_results_$form_id", apply_filters( 'gform_form_pre_results', $form ) );
This filter is located in GFResults::results_page() and GFResults::ajax_get_results() in includes/addon/class-gf-results.php.

gform_file_upload_status_markup

gform_file_upload_status_markup

DescriptionUsageParametersExamplesSinceSource Code

Description
JavaScript filter allowing the file upload markup to be filtered as it is being uploaded.
Usage

Parameters

statusMarkup string
Markup template used to render the status of the file being uploaded.

file {plupload.File}
Instance of File being uploaded. See: https://www.plupload.com/docs/v2/File.

size integer|string
File size.

strings object
Array of localized strings relating to the file upload UI.

removeFileJs string
JS used to remove the file when the 「Cancel」 link is click/pressed.

up {plupload.Uploader}
Instance of Uploader responsible for uploading current file. See: https://www.plupload.com/docs/v2/Uploader.

Examples

Since
This filter was added in Gravity Forms version 2.4.8.3.
Source Code
This filter is located in gravityforms/js/gravityforms.js.

gform_form_list_columns

gform_form_list_columns

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Allows the column headers displayed on the Form List page to be modified.
Usage
add_filter( 'gform_form_list_columns', 'your_function_name', 10, 1 );

Parameters

$columns
An array of the columns to display.
//default values
array(
'cb' => '',
'is_active' => '',
'title' => esc_html__( 'Title', 'gravityforms' ),
'id' => esc_html__( 'ID', 'gravityforms' ),
'entry_count' => esc_html__( 'Entries', 'gravityforms' ),
'view_count' => esc_html__( 'Views', 'gravityforms' ),
'conversion' => esc_html__( 'Conversion', 'gravityforms' ),
);

Examples
This example renames Title to Form Title, removes the column for the checkbox to apply actions, removes entry count, removes view count, and removes the conversion.
add_filter( 'gform_form_list_columns', 'change_columns', 10, 1 );
function change_columns( $columns ){
$columns = array(
'is_active' => '',
'id' => esc_html__( 'ID', 'gravityforms' ),
'title' => esc_html__( 'Form Title', 'gravityforms' ),
);
return $columns;
}

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.
Source Code
This filter is located in GF_Form_List_Table::get_columns() in form_list.php.

gform_field_types_delete_files

gform_field_types_delete_files

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Allows additional files to be deleted when file deletion occurs by adding additional field types.
Usage
The following would apply to all forms.
1add_filter( 'gform_field_types_delete_files', 'your_function_name', 10, 2 );
To target a specific form, append the form id to the hook name. (format: gform_field_types_delete_files_FORMID)
1add_filter( 'gform_field_types_delete_files_1', 'your_function_name', 10, 2 );

Parameters

$field_types array
Field types which contain file uploads.

$form Form Object
The current form.

Examples
The following example will allow you to keep files associated to entries after deleting the entries.
1add_filter( 'gform_field_types_delete_files', '__return_empty_array' );
The following example adds the post_custom_field to the field types to be removed.
12345add_filter( 'gform_field_types_delete_files', 'delete_custom_field_upload' );        function delete_custom_field_upload( $field_types ) {            $field_types[] = 'post_custom_field';            return $field_types;        }
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.10.
Source Code
This filter is located in:

GFFormsModel::get_delete_file_field_types() in forms_model.php
GFFormsModel::get_delete_file_field_types() in forms_model_legacy.php

gform_force_hooks_js_output

gform_force_hooks_js_output

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description

The gform_force_hooks_js_output filter can be used to prevent the Gravity Forms scripts from being injected into the pages if they』re not necessary.

Usage

1add_filter( 'gform_force_hooks_js_output', 'your_function_name' );

Parameters

Defaults to true. Set to false using __return_false or a custom function to set to false.

Examples

1add_filter( 'gform_force_hooks_js_output', '__return_false' );

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.5.3.1.

Source Code

This filter is located in Gravity_FormsGravity_FormsLibrariesDom_Parser::get_injected_html() in includes/libraries/class-dom-parser.php and GFForms::localize_hook_vars() in gravityforms.php.