Documentation

gform_confirmation

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. 1. Multiple forms.
    2. 2. Send entry data to third-party
    3. 3. Output script with confirmation message
  5. Placement
  6. Source 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

    Current form.

  • $entry Entry Object

    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 = 'Your download should begin shortly.' .
                    "<script>jQuery(document).bind('gform_confirmation_loaded', function () {window.open('http://domain.com/{$entry['10']}');});</script>";

    return $confirmation;
}


Placement

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


Source Code

This filter is located in GFFormDisplay::handle_confirmation() in form_display.php