gform_repeater_item_pre_add

gform_repeater_item_pre_add

DescriptionUsageParametersExamplePlacementSource Code

Description
This JavaScript hook can be used to filter new Repeater Field groups before they are added.
Usage
gform.addFilter( 'gform_repeater_item_pre_add', function ( clone, item ) {
// do stuff
return clone;
} );

Parameters

clone Javascript Object
The group of Repeater Field items.

item Javascript Object
The group of Repeater Field items before being cloned and the inputs cleared.

Example
This example shows how you can set the value of the second input in a Repeater Field group.

Placement
Your code snippet can be placed in a HTML field on your form or in a theme custom JavaScript file.
Source Code
This filter is located in js/gravityforms.js.

gform_register_init_scripts

gform_register_init_scripts

DescriptionUsageParametersExamplesPlacementSource Code

Description
Tap into Gravity Forms 「initialization scripts」 functionality and register your own scripts to run inline with Gravity Forms. Scripts added via the GFFormDisplay::add_init_script() function will be output with the form(s) they are registered for.
Usage
Applies to all forms.
1add_action( 'gform_register_init_scripts', 'my_custom_function', 10, 2 );

Parameters

$form Form Object
The current form.

$field_values array
If any field values were provided in the shortcode or functional call responsible for displaying this form, they will be available here.

Examples
This example (via Gravity Wiz), demonstrates how the gform_register_init_scripts hook can be used to register your GF-related initialization scripts using the GFFormDisplay::add_init_script() function.
12345678910111213add_action( 'gform_register_init_scripts', 'gform_format_money' );function gform_format_money( $form ) {     $script = '(function($){' .        '$('.gf_money input').each(function(){' .            '$(this).val(gformFormatMoney($(this).val()));' .        '}).change(function(){' .            '$(this).val(gformFormatMoney($(this).val()));' .        '});' .    '})(jQuery);';     GFFormDisplay::add_init_script( $form['id'], 'format_money', GFFormDisplay::ON_PAGE_RENDER, $script );}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFFormDisplay::register_form_init_scripts() in form_display.php.

gform_recaptcha_language

gform_recaptcha_language

DescriptionUsageParametersExamplesPlacementSource Code

Description
Use this filter to change the language used for the reCAPTCHA field.

Important: This filter has been removed. The recaptcha language can be configured in the form editor by editing the field or by using the gform_pre_render filter to set the $field->captchaLanguage property.

Usage
123
Parameters

$language string
Must be a language code supported by Google reCAPTCHA – https://developers.google.com/recaptcha/docs/language

$form_id integer
The current Form ID.

Examples
This example changes the language used for the reCAPTCHA field to Brazilian Portuguese.
12345678
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in includes/fields/class-gf-field-captcha.php

gform_recaptcha_init_script

gform_recaptcha_init_script

DescriptionUsageParametersExamplesV1 reCAPTCHAV2 reCAPTCHAPlacementSource Code

Description

This filter is no longer available since Gravity Forms 2.0.

Use this filter to change the look and feel of the reCAPTCHA field.
Usage
1add_filter( 'gform_recaptcha_init_script', 'custom_translation', 10, 3 );
Parameters

$script string
No value currently passed.

$form_id integer
The current Form ID.

$field Field Object
The field that recaptcha applies to.

Examples
This example changes the text displayed in the reCaptcha box to Italian translations, and also changes the theme from the default red one to white. This only works with V1 of reCAPTCHA.
V1 reCAPTCHA
123456789101112131415add_filter( 'gform_recaptcha_init_script', 'custom_translation', 10, 3 );function custom_translation( $script, $form_id, $field ) {    $script = 'RecaptchaOptions.custom_translations = {            instructions_visual : "Scrivi le due parole:",            instructions_audio : "Trascrivi ciu00f2 che senti:",            play_again : "Riascolta la traccia audio",            cant_hear_this : "Scarica la traccia in formato MP3",            visual_challenge : "Modalitu00e0 visiva",            audio_challenge : "Modalitu00e0 auditiva",            refresh_btn : "Chiedi due nuove parole",            help_btn : "Aiuto",            incorrect_try_again : "Scorretto. Riprova."        };RecaptchaOptions.theme = "white"';    return $script;}
V2 reCAPTCHA
This version of reCAPTCHA is planned to be released with Gravity Forms 2.0 and new reCAPTCHA fields added will use this version. There are only a few customizations that may be done in this version. Please see https://developers.google.com/recaptcha/docs/display for more details.
The example below changes the theme (dark vs. light default) and the type (audio vs. image default).
12345add_filter( 'gform_recaptcha_init_script','custom_translation', 10, 3 );function custom_translation( $script, $form_id, $field ) {    $script = 'RecaptchaOptions.theme = "dark";RecaptchaOptions.type = "audio"';    return $script;}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GF_Field_CAPTCHA::get_field_input() in includes/fields/class-gf-field-captcha.php

gform_recaptcha_callback

gform_recaptcha_callback

DescriptionUsageParametersExample1. Add the script via the gform_pre_render hookPlacementSource Code

Description
The 「gform_recaptcha_callback」 JavaScript filter in Gravity Forms allows a custom callback function to be executed when the user successfully submits the captcha.
Usage
12345gform.addFilter( 'gform_recaptcha_callback', function( callback, elem) {    // do stuff      return callback;} );

Parameters

type string or boolean
The name of the callback function to be executed when the user successfully submits the captcha.

elem object
The jQuery object containing the div element with the ginput_recaptcha class for the current reCaptcha field.

Example
1. Add the script via the gform_pre_render hook
1234567891011121314add_action( 'gform_pre_render', 'set_callback' );function set_callback( $form ) {    ?>        

gform_quiz_show_choice_values

gform_quiz_show_choice_values

DescriptionUsageExamplesPlacementSource Code

Description
This filter controls whether the values for the answer choices may be modified in the Form Editor. By default, the ability to set values is not available.
Warning: Editing the values after entries have been submitted will affect the integrity of the results. Delete all entries for the form before editing the values.
Usage
add_filter( 'gform_quiz_show_choice_values', 'gquiz_show_values' );

Examples
add_filter( 'gform_quiz_show_choice_values', 'gquiz_show_values' );
function gquiz_show_values(){
return true;
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFQuiz::quiz_field_settings() in gravityformsquiz/class-gf-quiz.php.

gform_purge_expired_incomplete_submissions_query

gform_purge_expired_incomplete_submissions_query

DescriptionUsageParametersPlacementSinceSource Code

Description
Allows the query used to purge expired incomplete (save and continue) submissions to be overridden.
Usage
add_filter( 'gform_purge_expired_incomplete_submissions_query', 'your_function_name', 10 );

Parameters

$query array
The delete, from, and where arguments to be used when the query is performed.

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in v2.1.1.20.
Source Code
$query = array(
'delete' => 'DELETE',
'from' => sprintf( 'FROM %s', self::get_incomplete_submissions_table_name() ),
'where' => $wpdb->prepare( 'WHERE date_created < %s', $expiration_date ), ); $query = apply_filters( 'gform_purge_expired_incomplete_submissions_query', $query ); $result = $wpdb->query( implode( "n", $query ) );

This filter is located in GFFormsModel::purge_expired_incomplete_submissions() in forms_model.php.

gform_progressbar_start_at_zero

gform_progressbar_start_at_zero

DescriptionUsagePlacementSinceSource Code

Description
Use this filter to change the progress bar on multi-page forms to start at zero percent. By default, the progress bar starts as if your first step has been completed.
Usage
1add_filter( 'gform_progressbar_start_at_zero', '__return_true' );
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.6.3.
Source Code
This filter is located in the following methods in form_display.php:

GFFormDisplay::get_form()
GFFormDisplay::get_progress_bar()

gform_progress_steps

gform_progress_steps

DescriptionUsageParametersExamples1. Add a custom class to the active step.Source CodeSince

Description
The gform_progress_steps filter can be used to modify or replace the default progress steps markup for multi-page forms.
Usage
The following would apply to all forms.
1add_filter( 'gform_progress_steps', 'your_function_name', 10, 3 );
To limit the scope of your function to a specific form, append the form id to the end of the hook name. (format: gform_progress_steps_FORMID)
1add_filter( 'gform_progress_steps_5', 'your_function_name', 10, 3 );

Parameters

$progress_steps string
HTML string containing the progress steps markup.

$form Form Object
The current form object.

$page integer
The current page number.

Examples
1. Add a custom class to the active step.
1234567add_filter( 'gform_progress_steps', 'progress_steps_markup', 10, 3 );function progress_steps_markup( $progress_steps, $form, $page ) {    $active_class = 'gf_step_active';    $progress_steps = str_replace( $active_class, $active_class . ' your_custom_class', $progress_steps );     return $progress_steps;}
Source Code
This filter is located in GFFormDisplay::get_progress_steps() in form_display.php.
Since
This filter was added in Gravity Forms 2.0-beta-3.

gform_progress_bar

gform_progress_bar

DescriptionUsageParametersExamples1. Generate custom progress bar markup2. Replace Step with LevelPlacementSinceSource Code

Description

Use this filter to modify or replace the default Gravity Forms progress bar (for multi-page forms).

Usage

Apply to all forms.

add_filter( 'gform_progress_bar', 'my_custom_function', 10, 3 );

Apply to specific forms.

// templateadd_filter( 'gform_progress_bar_{formId}', 'my_custom_function', 10, 3 );  // target form ID 1add_filter( 'gform_progress_bar_1', 'my_custom_function', 10, 3 );

Parameters

$progress_bar stringProgress bar markup as an HTML string.$form Form ObjectCurrent Form object.$confirmation_message stringThe confirmation message to be displayed on the confirmation page.

Examples

1. Generate custom progress bar markup

add_filter( 'gform_progress_bar', function( $progress_bar, $form, $confirmation_message ) {      $progress_bar = '

            

  • Page 1
  •         

  • Page 2
  •         

  • Page 3
  •     

';      return $progress_bar; }, 10, 3 );

2. Replace Step with Level

add_filter( 'gform_progress_bar', function( $progress_bar, $form, $confirmation_message ) {    $progress_bar = str_replace( 'Step', 'Level', $progress_bar );    return $progress_bar;}, 10, 3 );

Placement

This code should be placed in the functions.php file of your active theme.

Since

This filter was added in Gravity Forms 2.0.

Source Code

This filter is located in the GFFormDisplay class in form_display.php.