Using Gravity Forms ‘gform_pre_confirmation_save’ PHP action

The gform_pre_confirmation_save Gravity Forms PHP filter allows you to modify the confirmation object before it is saved to the database.

Usage

To apply the filter to all forms:

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

To apply the filter to a specific form with ID 5:

add_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.

More information

See Gravity Forms Docs: gform_pre_confirmation_save

Examples

Add custom confirmation setting

This example demonstrates how to add the value entered via a custom UI setting to the confirmation object before it is saved to the database. Use this with the gform_confirmation_ui_settings hook to display your custom settings UI.

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

Modify confirmation message based on form input

This example shows how to modify the confirmation message based on a user’s input on the form.

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

function customize_confirmation_message($confirmation, $form) {
    $user_input = rgpost('input_1');
    $confirmation['message'] .= ' ' . $user_input;
    return $confirmation;
}

Conditional confirmation redirect

This example demonstrates how to conditionally redirect users to different pages based on their form input.

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

function conditional_confirmation_redirect($confirmation, $form) {
    $user_choice = rgpost('input_1');
    if ($user_choice == 'Option A') {
        $confirmation['url'] = 'https://www.example.com/page-a';
    } else {
        $confirmation['url'] = 'https://www.example.com/page-b';
    }
    return $confirmation;
}

Change confirmation type based on form input

This example shows how to change the confirmation type (message, redirect, or page) based on a user’s input on the form.

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

function change_confirmation_type($confirmation, $form) {
    $user_input = rgpost('input_1');
    if ($user_input == 'Yes') {
        $confirmation['type'] = 'redirect';
        $confirmation['url'] = 'https://www.example.com/yes-page';
    } else {
        $confirmation['type'] = 'message';
        $confirmation['message'] = 'Thanks for your response!';
    }
    return $confirmation;
}