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_pre_confirmation_save

gform_pre_confirmation_save

DescriptionUsageParametersExamplesSource Code

Description
Modify the confirmation object before it is saved to the database. This is particularly useful when saving custom confirmation settings to the confirmation object.
Usage
Apply to all forms:
1add_filter( 'gform_pre_confirmation_save', 'my_custom_function', 10, 2 );
Apply to a specific form ID:
1add_filter( 'gform_pre_confirmation_save_5', 'my_custom_function', 10, 2 );
Parameters

$confirmation Confirmation Object
The confirmation object about to be saved.

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

Examples
This example demonstrates how you can add the value entered via our gform_confirmation_ui_settings to the confirmation object before it is saved to the database. Use with the gform_confirmation_ui_settings hook to display your custom settings UI.
If your UI settings have a 「name」 attribute, they will be submitted along with the rest of the default confirmation settings. We can then retrieve our custom value from the $_POST using the Gravity Forms helper function rgpost().
12345add_filter( 'gform_pre_confirmation_save', 'my_custom_confirmation_save', 10, 2 );function my_custom_confirmation_save( $confirmation, $form ) {    $confirmation['my_custom_setting'] = rgpost( 'my_custom_setting' );    return $confirmation;}
Source Code
This filter is located in GFFormSettings::handle_confirmation_edit_submission() in form_settings.php.

gform_confirmation_anchor

gform_confirmation_anchor

DescriptionUsageParametersExamples1. Enable for all forms2. Disable for a specific form3. Set scroll distancePlacementSinceSource Code

Description
Use this filter to enable or disable the confirmation anchor functionality that automatically scrolls the page to the confirmation text or validation message upon submission. This also takes effect when browsing between pages of a multi-page form. The page may also be forced to scroll to a specified distance (pixel) from the top of the page. This hook is useful when embedding forms in a long page.
When the anchor exists, the page scrolls to the top of the form. For non-AJAX forms without the anchor, the page remains at the top of the page upon reload. For AJAX forms without the anchor, the page will not move when the form content is updated. Depending on the page layout, padding and margin changes associated with displaying validation errors may make it appear that the page has scrolled.
When the anchor is set to true, the following HTML is added before the opening form tag.
12//the 80 is the form id

When true, the bookmark for the anchor (#gf_80 in this example) is also added to the action on the form tag.
12

Usage
The following would apply to all forms:
1add_filter( 'gform_confirmation_anchor', 'your_function_name' );
To target a specific form append the form id to the hook name. (format: gform_confirmation_anchor_FORMID)
1add_filter( 'gform_confirmation_anchor_5', 'your_function_name' );

Parameters

$anchor bool/int
Indicates how the anchor will behave. The default is true when AJAX is enabled or for multi-page non-AJAX forms (anchor present), and false for single page non-AJAX forms (no anchor).

Set $anchor to true -> Page will scroll to the position where the form is located.
Set $anchor to false -> Page will not scroll. For AJAX forms, the page scroll position won』t change when the form is submitted. For non-AJAX forms, the page will remain at the top of document after being reloaded.
Set $anchor to any numeric value -> Page will be scrolled to the specified pixel value from the top of the document.

$form Form Object
The current form. Available from Gravity Forms 1.9.17.12.

Examples
1. Enable for all forms
The following example enables the confirmation anchor on all forms.
1add_filter( 'gform_confirmation_anchor', '__return_true' );
2. Disable for a specific form
The following example disables the confirmation anchor for form with ID 5.
1add_filter( 'gform_confirmation_anchor_5', '__return_false' );
3. Set scroll distance
The following example causes all AJAX enabled forms to scroll to 20 pixels from the top of the document after being submitted. Only AJAX enabled forms can set the scroll distance.
123add_filter( 'gform_confirmation_anchor', function() {    return 20;} );
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.3.13.
Ability to pass an integer for $anchor added in version 1.6.
$form parameter added in version 1.9.17.12.
Source Code
This filter is located in the following methods in form_display.php:

GFFormDisplay::get_form()
GFFormDisplay::get_confirmation_message()
GFFormDisplay::replace_save_variables()
GFFormDisplay::handle_save_email_confirmation()
GFFormDisplay::handle_save_confirmation()

gform_confirmation_actions

gform_confirmation_actions

DescriptionUsageParametersExamplesSource Code

Description
Modify the list of actions which display below the Confirmation Name on the Confirmations list view.
Usage
add_action( 'gform_confirmation_actions', 'my_custom_function' );

Parameters

$actions array
An array of current confirmation actions.

Examples
This example demonstrates how you can add custom confirmation actions.
Please note: the myCustomDuplicateConfirmationFunction() does not exist so the form will not actually be duplicated if you add this code sample.
add_action( 'gform_confirmation_actions', 'my_custom_confirmation_action' );
function my_custom_confirmation_action( $actions ) {

// adds a 'duplicate' action with a link that triggers some functionaliy on click
$actions['duplicate'] = 'Duplicate';

return $actions;
}

Source Code
This filter is located in GFConfirmationTable::column_name() in form_settings.php.

gform_conditional_logic_values_input

gform_conditional_logic_values_input

DescriptionUsageParametersExamplePlacementSinceSource Code

Description

The gform_conditional_logic_values_input JavaScript filter in Gravity Forms allows filtering the input string provided for the conditional logic comparison value.

Usage

gform.addFilter( 'gform_conditional_logic_values_input', function( str, objectType, ruleIndex, selectedFieldId, selectedValue ) {
// do stuff

return str;
} );

Parameters

str stringString of the HTML input tag.objectType stringThe type of object: page, field, next_button, confirmation, notification.ruleIndex intThe index of the rule. The first rule is indexed at 0.selectedFieldId intThe ID of the field chosen for comparison.selectedValue stringThe value used for comparison.

Example

add_action( 'admin_print_scripts', function () {

if ( method_exists( 'GFForms', 'is_gravity_page' ) && GFForms::is_gravity_page() ) { ?>

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.

gform_conditional_logic_fields

gform_conditional_logic_fields

DescriptionUsageParametersExamplePlacementSinceSource Code

Description

The gform_conditional_logic_fields JavaScript filter in Gravity Forms allows filtering which fields are available for conditional logic and adding custom fields to conditional logic.

Usage

gform.addFilter( 'gform_conditional_logic_fields', function( options, form, selectedFieldId ) {
// do stuff

return options;
} );

Parameters

options arrayAn array consisting of each conditional logic field with its label and field id.form Form ObjectThe current form.selectedFieldId intThe ID of the selected field.

Example

add_action( 'admin_print_scripts', function () {

if ( method_exists( 'GFForms', 'is_gravity_page' ) && GFForms::is_gravity_page() ) { ?>