Using Gravity Forms ‘gform_confirmation_before_save’ PHP filter

The gform_confirmation_before_save filter in Gravity Forms allows you to modify the confirmation object before it’s stored in the database. This is particularly handy when you want to save custom confirmation settings to the confirmation object.

Usage

To apply this filter to all forms, use:

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

To apply it to a specific form (for example, form ID 5), use:

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

Parameters

  • $confirmation (Confirmation Object): The confirmation object that’s 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_confirmation_before_save

This filter is found in GFFormSettings::handle_confirmation_edit_submission() in the form_settings.php file.

Examples

Adding Custom Confirmation Setting

This example shows how to add a custom confirmation setting to the confirmation object before saving. We use the rgpost() helper function to retrieve our custom value from the $_POST.

add_filter( 'gform_pre_confirmation_save', 'my_custom_confirmation_save', 10, 2 );
function my_custom_confirmation_save( $confirmation, $form ) {
    // your custom code here
    $confirmation['my_custom_setting'] = rgpost( 'my_custom_setting' );
    // returns the confirmation object with the added custom setting
    return $confirmation;
}

Saving Additional Data with Confirmation

This example shows how you can save additional data with the confirmation. Here, we are saving the form’s title along with the confirmation.

add_filter( 'gform_pre_confirmation_save', 'save_form_title_with_confirmation', 10, 2 );
function save_form_title_with_confirmation( $confirmation, $form ) {
    // your custom code here
    $confirmation['form_title'] = $form['title'];
    // returns the confirmation object with the added form title
    return $confirmation;
}

Setting Custom Confirmation Based on Form ID

This example sets a custom confirmation message for a form with a specific ID.

add_filter( 'gform_pre_confirmation_save_5', 'set_custom_confirmation_for_form_5', 10, 2 );
function set_custom_confirmation_for_form_5( $confirmation, $form ) {
    // your custom code here
    $confirmation['message'] = "Thank you for your submission!";
    // returns the confirmation object with the custom message
    return $confirmation;
}

Modifying Confirmation Redirect URL

This example modifies the redirect URL in the confirmation object before saving it.

add_filter( 'gform_pre_confirmation_save', 'modify_confirmation_redirect', 10, 2 );
function modify_confirmation_redirect( $confirmation, $form ) {
    // your custom code here
    $confirmation['url'] = "https://your-new-redirect-url.com";
    // returns the confirmation object with the modified redirect URL
    return $confirmation;
}