Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Uses the gform_confirmation hook to display a text confirmation message before triggering the redirect confirmation.
<?php
// Copy everything below this line
/**
* GravityRanger Dual Confirmation (text + redirect)
* https://gravityranger.com/display-text-confirmation-before-redirecting-gravity-forms
*
* Uses the gform_confirmation hook to display a text confirmation message before triggering the redirect confirmation.
* This code is a modified version of the snippet provided on docs.gravityfroms.com
*
* @instructions:
*
* 1. Add this code snippet to your functions.php file or a functionality plugin like WPCodeBox
* 2. Enter your form ID number(s) on line 31
* 3. Edit the confirmation message on line 40
* 4. Set how many seconds you want the redirect to be delaied on line 42 (2000 = 2 seconds)
* NOTE: This only works if your default confirmation is configured as a redirect
*
*
* @version 0.1
* @author GravityRanger
* @license GPL-2.0+
* @link http://gravityranger.com/
* @credits https://docs.gravityforms.com/gform_confirmation/
*
*/
add_filter( 'gform_confirmation', function ( $confirmation, $form, $entry, $ajax ) {
GFCommon::log_debug( __METHOD__ . '(): running.' );
$forms = array( 5, 16, 43 ); // i.e Targets forms with id 5, 16 and 43.
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 = 'Your message has been received loud and clear. Please standby...';
$confirmation .= "<script type=\"text/javascript\">
setTimeout(function() { window.open('$url')}, 2000); </script>";
}
return $confirmation;
}, 10, 4 );
@earwickerh
Copy link

earwickerh commented May 4, 2022

Awesome, thanks Chris! How could I use this in the "Save and Continue Email Sent Confirmation" instead of the default submission confirmation? Any guidance would be really appreciated. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment