gform_pre_confirmation_save

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:

add_filter( 'gform_pre_confirmation_save', 'my_custom_function', 10, 2 );

Apply to a specific form ID:

add_filter( 'gform_pre_confirmation_save_5', 'my_custom_function', 10, 2 );

Parameters

Here’s the table in HTML preview format with links preserved:

ParameterTypeDescription
$confirmationConfirmation ObjectThe confirmation object about to be saved.
$formForm ObjectThe current form object to which the confirmation being saved belongs.
$is_new_confirmationboolTrue if this is a new confirmation. False if editing existing.

Examples

This example demonstrates how you can add the value entered via the gform_confirmation_settings_fields filter to the confirmation object before it is saved to the database. Use with the gform_confirmation_settings_fields 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().

add_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;
}

To add the custom setting field to the confirmation settings UI, use the gform_confirmation_settings_fields filter:

add_filter( 'gform_confirmation_settings_fields', function( $fields, $confirmation, $form ) {
    $fields[0]['fields'][] = array(
        'type'  => 'text',
        'name'  => 'my_custom_setting',
        'label' => 'My Custom Setting',
    );

    return $fields;
}, 10, 3 );

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

This filter is located in GFFormSettings::handle_confirmation_edit_submission() in form_settings.php.