gravity forms redirect open new tab code example

Example: gravity forms redirect open new tab

add_filter( 'gform_confirmation', function ( $confirmation, $form, $entry, $ajax ) {
    GFCommon::log_debug( __METHOD__ . '(): running.' );
 
    $forms = array( 3, 6, 7 ); // Target forms with id 3, 6 and 7. Change this to fit your needs.
 
    if ( ! in_array( $form['id'], $forms, true ) ) {
        return $confirmation;
    }
 
    if ( isset( $confirmation['redirect'] ) ) {
        $url          = esc_url_raw( $confirmation['redirect'] );
        GFCommon::log_debug( __METHOD__ . '(): Redirect to URL: ' . $url );
        $confirmation = 'Thanks for contacting us! We will get in touch with you shortly.';
        $confirmation .= "<script type=\"text/javascript\">window.open('$url', '_blank');</script>";
    }
 
    return $confirmation;
}, 10, 4 );

Tags:

Misc Example