gform_confirmation_settings_fields

gform_confirmation_settings_fields

DescriptionUsageParametersExamples1. Add a new fieldPlacementSinceSource Code

Description
The gform_confirmation_settings_fields filter allows the confirmation settings fields to be modified before they are displayed.
Usage
The filter which would run for all forms would be used like so:
add_filter( 'gform_confirmation_settings_fields', 'your_function_name', 10, 3 );

You can also target a specific form by adding the form id after the hook name.
add_filter( 'gform_confirmation_settings_fields_6', 'your_function_name', 10, 3 );

Parameters

$fields array
The confirmation settings fields. See the Settings API for details about how the fields are defined.

$confirmation Confirmation Object
The meta for the form confirmation being viewed/edited.

$form Form Object
The current form.

Examples
1. Add a new field
This example shows how to add a new hidden type setting.
add_filter( 'gform_confirmation_settings_fields', function ( $fields, $confirmation, $form ) {
$fields[0]['fields'][] = array( 'type' => 'hidden', 'name' => 'my_custom_hidden_field' );

return $fields;
}, 10, 3 );

Placement
This code should be placed in the functions.php file of your active theme or a custom functions plugin.
Since
This filter was added in Gravity Forms v2.5.
Source Code
This filter is located in GF_Confirmation::settings_fields() in includes/class-confirmation.php.

gform_confirmation_ui_settings

gform_confirmation_ui_settings

DescriptionUsageParametersExamplesSource Code

Description
Add new or modify existing confirmation settings that display on the Confirmation Edit screen.

This filter is deprecated in Gravity Forms 2.5 and greater. Use the gform_confirmation_settings_fields filter instead.

Usage
Apply to all forms:
add_filter( 'gform_confirmation_ui_settings', 'my_custom_function', 10, 3 );

Apply to a specific form ID:
add_filter( 'gform_confirmation_ui_settings_5', 'my_custom_function', 10, 3 );

Parameters

$ui_settings array
An array of settings for the confirmation UI. Each setting contains the HTML which will be displayed for that setting.

$confirmation Confirmation Object
The current confirmation object being edited.

$form Form Object
The current form object to which the confirmation being edited belongs.

Examples
This example demonstrates how you can add custom confirmation UI setting. Use with the gform_confirmation_before_save hook to save your custom settings.
add_filter( 'gform_confirmation_ui_settings', 'my_custom_confirmation_setting', 10, 3 );
function my_custom_confirmation_setting( $ui_settings, $confirmation, $form ) {

$ui_settings['my_custom_setting'] = '

';

return $ui_settings;
}

Source Code
This filter is located in GFFormSettings::get_confirmation_ui_settings() in form_settings.php.

gform_confirmation

gform_confirmation

DescriptionUsageParametersExamples1. Multiple forms2. Send entry data to third-party3. Output script with confirmation message4. Open the page or redirect in a new tab5. Customize the message for spam submissions6. Modify the confirmation query stringPlacementSource Code

Description
This filter can be used to dynamically change the confirmation message or redirect URL for a form.
Usage
add_filter( 'gform_confirmation', 'custom_confirmation', 10, 4 );

You can also specify this per form by adding the form id after the hook name.
add_filter( 'gform_confirmation_6', 'custom_confirmation', 10, 4 );

Parameters

$confirmation string | array
The confirmation message/array to be filtered. For a simple confirmation message, set this variable to the message you would like displayed in the screen. To redirect the page to an URL, set this variable to an array in the following format:
$confirmation = array( 'redirect' => 'http://www.google.com' );

$form Form Object
The current form.

$entry Entry Object
The current entry.

$is_ajax bool
Specifies if this form is configured to be submitted via AJAX.

Examples
1. Multiple forms
This example dynamically changes the confirmation message for form 102 and set form 101 to redirect to www.google.com.
add_filter( 'gform_confirmation', 'custom_confirmation', 10, 4 );
function custom_confirmation( $confirmation, $form, $entry, $ajax ) {
if( $form['id'] == '101' ) {
$confirmation = array( 'redirect' => 'http://www.google.com' );
} elseif( $form['id'] == '102' ) {
$confirmation = "Thanks for contacting us. We will get in touch with you soon";
}
return $confirmation;
}

2. Send entry data to third-party
This example demonstrates a simple approach to posting submitted entry data to a third party application. You could even assign some part of the response to the $confirmation message.
add_filter( 'gform_confirmation', 'post_to_third_party', 10, 3 );
function post_to_third_party( $confirmation, $form, $entry ) {

$post_url = 'http://thirdparty.com';
$body = array(
'first_name' => rgar( $entry, '1.3' ),
'last_name' => rgar( $entry, '1.6' ),
'message' => rgar( $entry, '3' ),
);
GFCommon::log_debug( 'gform_confirmation: body => ' . print_r( $body, true ) );

$request = new WP_Http();
$response = $request->post( $post_url, array( 'body' => $body ) );
GFCommon::log_debug( 'gform_confirmation: response => ' . print_r( $response, true ) );

return $confirmation;
}

3. Output script with confirmation message
The following example shows how you can output a script along with the form confirmation message.
add_filter( 'gform_confirmation_3', 'custom_confirmation_message', 10, 4 );
function custom_confirmation_message( $confirmation, $form, $entry, $ajax ) {
$confirmation .= "";

return $confirmation;
}

Note: This example uses also gform_confirmation_loaded, so AJAX must be enabled in your form.
4. Open the page or redirect in a new tab
The following example shows how you can open the 「page」 or 「redirect」 type confirmation in a new tab. You need to update the $forms array with the id number of the form(s) that you want to target.
add_filter( 'gform_confirmation', function ( $confirmation, $form, $entry, $ajax ) {
GFCommon::log_debug( __METHOD__ . '(): running.' );

$forms = array( 3, 6, 7 ); // Target forms with id 3, 6 and 7. Change this to fit your needs.

if ( ! in_array( $form['id'], $forms ) ) {
return $confirmation;
}

if ( isset( $confirmation['redirect'] ) ) {
$url = esc_url_raw( $confirmation['redirect'] );
GFCommon::log_debug( __METHOD__ . '(): Redirect to URL: ' . $url );
$confirmation = 'Thanks for contacting us! We will get in touch with you shortly.';
$confirmation .= "
Parameters

event JS Object | object
The Javascript event object.

formId integer
The ID of the form submitted.

Examples
This event is very useful when the popular font substitution script Cufon is being applied to a Gravity Form which uses the AJAX form submission functionality. The snippet below provides an example usage of the gform_confirmation_loaded event to refresh the Cufon font substitution when the confirmation page is loaded.
1234567
Here is another example where the form ID parameter is used to run different code depending on which form』s confirmation is being loaded.
12345678910111213
Source Code
This filter is located in form_display.php.

gform_checkbox_select_all_label

gform_checkbox_select_all_label

DescriptionUsageParametersExamples1. All forms2. Specific form3. Specific checkbox field on a formPlacementSinceSource Code

Description
The 「gform_checkbox_select_all_label」 filter in Gravity Forms allows the 「Select All」 label for the Checkboxes field to be modified.
Usage
The following would apply to all forms:
1add_filter( 'gform_checkbox_select_all_label', 'your_function_name', 10, 2 );
To target a specific form, append the form id to the hook name. (format: gform_checkbox_select_all_label_FORMID)
1add_filter( 'gform_checkbox_select_all_label_1', 'your_function_name', 10, 2 );
To target a specific field for a form, append the form id and field id to the hook name. (format: gform_checkbox_select_all_label_FORMID_FIELDID)
1add_filter( 'gform_checkbox_select_all_label_1_22', 'your_function_name', 10, 2 );

Parameters

$select_label string
The 「Select All」 label.

$field Field Object
The field object for the current field.

Examples
1. All forms
1234add_filter( 'gform_checkbox_select_all_label', 'change_label', 10, 2 );function change_label( $select_label, $field ){    return "My Custom Select All";}
2. Specific form
1234add_filter( 'gform_checkbox_select_all_label_114', 'change_label', 10, 2 );function change_label( $select_label, $field ){    return "My Custom Select All";}
3. Specific checkbox field on a form
1234add_filter( 'gform_checkbox_select_all_label_114_2', 'change_label', 10, 2 );function change_label( $select_label, $field ){    return "My Custom Select All";}
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.
Source Code
This filter is located in GF_Field_Checkbox::get_checkbox_choices() in gravityforms/fields/includes/class-gf-field-checkbox.php.

gform_chained_selects_input_choices

gform_chained_selects_input_choices

DescriptionUsageParametersExamples1. Populate Year, Make, and Model2. Define the default choicePlacementSource CodeSince

Description
The filter gform_chained_selects_input_choices is used to modify the choices that will appear in each drop down of a Chained Select field.

IMPORTANT: For obvious reasons, this filter can』t run when the page where your form is embedded is cached. This is not a Gravity Forms limitation but a consequence of using caching.

Usage
Filter all chained selects for all forms.
1add_action( 'gform_chained_selects_input_choices', 'your_function_name' );
Filter all chained selects for a specific form.
1add_action( 'gform_chained_selects_input_choices_6', 'your_function_name' );
Filter chained selects for a specific form and specific field.
1add_action( 'gform_chained_selects_input_choices_6_2', 'your_function_name' );
Filter a specific chained select for a specific form and field.
1add_action( 'gform_chained_selects_input_choices_6_2_1', 'your_function_name' );

Parameters

$input_choices array
An array of Choices that will be used to populate the current drop down.

$form_id integer
The form ID for the current form.

$field Field Object
The current field object.

$input_id float
The input ID of the current input (i.e. drop down) being processed. Example: 3.1.

$full_chain_value array
An array of values representing the selected value for each input in the chain of selects. Example:
12345array(    '3.1' => 'Toyota',    '3.2' => 'Matrix',    '3.3' => 2013);

$value string
The value of the current chained select.

$index int – Added in version 1.1.
The index of the specific chained select.

Examples
1. Populate Year, Make, and Model
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384// populates the "Make" drop down of our Chained Selectadd_filter( 'gform_chained_selects_input_choices_855_14_1', 'gf_populate_makes', 10, 7 );function gf_populate_makes( $input_choices, $form_id, $field, $input_id, $chain_value, $value, $index ) {     $api_key = '9du7r286jng2zjjaf8antxur'; // signup for your own Edmunds API key here: http://edmunds.mashery.com/member/register    $choices = array();     $response = wp_remote_get( "https://api.edmunds.com/api/vehicle/v2/makes?state=new&year=" . date( 'Y' ) . "&view=basic&fmt=json&api_key={$api_key}" );    if ( wp_remote_retrieve_response_code( $response ) != 200 ) {        return $input_choices;    }     $makes = json_decode( wp_remote_retrieve_body( $response ) )->makes;    foreach( $makes as $make ) {        $choices[] = array(            'text'       => $make->name,            'value'      => $make->niceName,            'isSelected' => false        );    }     return $choices;} // populates the "Model" drop down of our Chained Selectadd_filter( 'gform_chained_selects_input_choices_855_14_2', 'gf_populate_models', 10, 7 );function gf_populate_models( $input_choices, $form_id, $field, $input_id, $chain_value, $value, $index ) {     $api_key = '9du7r286jng2zjjaf8antxur'; // signup for your own Edmunds API key here: http://edmunds.mashery.com/member/register    $choices = array();     $selected_make = $chain_value[ "{$field->id}.1" ];    if( ! $selected_make ) {        return $input_choices;    }     $response = wp_remote_get( "https://api.edmunds.com/api/vehicle/v2/{$selected_make}/models?view=basic&fmt=json&api_key={$api_key}" );    if ( wp_remote_retrieve_response_code( $response ) != 200 ) {        return $input_choices;    }     $models = json_decode( wp_remote_retrieve_body( $response ) )->models;    foreach( $models as $model ) {        $choices[] = array(            'text'       => $model->name,            'value'      => $model->niceName,            'isSelected' => false        );    }     return $choices;} // populates the "Year" drop down of our Chained Selectadd_filter( 'gform_chained_selects_input_choices_855_14_3', 'gf_populate_years', 10, 7 );function gf_populate_years( $input_choices, $form_id, $field, $input_id, $chain_value, $value, $index ) {     $api_key = '9du7r286jng2zjjaf8antxur'; // signup for your own Edmunds API key here: http://edmunds.mashery.com/member/register    $choices = array();     $selected_make  = $chain_value[ "{$field->id}.1" ];    $selected_model = $chain_value[ "{$field->id}.2" ];    if( ! $selected_make || ! $selected_model ) {        return $input_choices;    }     $response = wp_remote_get( "https://api.edmunds.com/api/vehicle/v2/{$selected_make}/{$selected_model}/years/count?view=full&fmt=json&api_key={$api_key}" );    if ( wp_remote_retrieve_response_code( $response ) != 200 ) {        return $input_choices;    }     $years = wp_list_pluck( json_decode( wp_remote_retrieve_body( $response ) )->years, 'year' );    rsort( $years );     foreach( $years as $year ) {        $choices[] = array(            'text'       => $year,            'value'      => $year,            'isSelected' => false        );    }     return $choices;}
2. Define the default choice
The following example shows how you can define which choice in the drop down should be selected by default. In this case we are setting the second choice as the default choice in the third drop down of field 1 on form 123.
1234add_filter( 'gform_chained_selects_input_choices_123_1_3', function( $choices ) {    $choices[1]['isSelected'] = true;    return $choices;} );
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
1$input_choices = gf_apply_filters( 'gform_chained_selects_input_choices', array( $this->formId, $this->id, $index ), $input_choices, $this->formId, $this, $input_id, $full_chain_value, $value, $index );
This hook is located in GF_Chained_Field_Select::get_input_choices() in class-gf-field-chained-select.php.
Since

The form specific version of this hook was added in Gravity Forms Chained Selects 1.0.
The $index parameter was added in version 1.1.

gform_conditional_logic_operators

gform_conditional_logic_operators

DescriptionUsageParametersExamplesSource Code

Description

This JavaScript hook can be used to override the available conditional logic operators.

Usage

gform.addFilter('gform_conditional_logic_operators', function (operators, objectType, fieldId) {
// do stuff
return $operators;
});

Parameters

operators Javascript Object
The current operators. e.g.
{"is":"is","isnot":"isNot", ">":"greaterThan", "<":"lessThan", "contains":"contains", "starts_with":"startsWith", "ends_with":"endsWith"} objectType string The current conditional logic object type. Possible values: page, field, next_button, confirmation, notification, or feed_condition. fieldId integer The ID of the current field. Examples The following example shows how you can specify the available operators. gform.addFilter('gform_conditional_logic_operators', function (operators, objectType, fieldId) { operators = {'>': 'greaterThan'};

return operators;
});

Source Code

This hook is located in GetRuleOperators() in js/form_admin.js.