Contact Form 7 Redirect to Confirmation Page

To redirect Contact Form 7 to a single confirmation page, or multiple confirmation pages by form ID add the following PHP snippet to your WordPress theme’s function.php file: –

Redirect Contact Form 7 to a single confirmation page

add_action( 'wp_footer', 'redirect_cf7' );
function redirect_cf7() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
       location = 'https://yourdomain.com/confirmation/';
}, false );
</script>
<?php
}

Change ‘https://yourdomain.com/confirmation/’ to reflect your own confirmation page URL

Redirect Contact Form 7 to multiple confirmation pages

add_action( 'wp_footer', 'redirect_cf7' );
function redirect_cf7() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
   if ( '119' == event.detail.contactFormId ) { // Sends confirmation for form ID 119
    location = 'https://yourdomain.com/confirmation-1';
    } else if ( '120' == event.detail.contactFormId ) { // Sends confirmation for form ID 120
        location = 'https://yourdomain.com/confirmation-2/';
    } else { // Sends 'catch all' confirmation for all unaccounted contact forms
        location = 'https://yourdomain.com/confirmation/';
    }
}, false );
</script>
<?php
}

In this instance ‘119’, ‘120’are the Contact Form 7 IDs so you will need to extrapolate your own IDs and these are clearly displayed under Contact > Contact Forms in the displayed forms ‘shortcode’ ‘[contact-form-7 id=”119″ title=”Contact form 1″]’ and also when you edit the form it’s shown in the URL i.e. /wp-admin/admin.php?page=wpcf7&post=119&action=edit

About the Author
Contact Form 7 Redirect to Confirmation Page 0da77002febbfe28d15144a57bbcc2c9 s 180 d mm r g

Glenn

A highly experienced Web Designer / Web Developer (Webflow, WordPress, Weebly & Custom), Front-end / Back-end Developer & New Media Specialist, with extensive knowledge of a wide spectrum of technologies in the Development and Creative Industries, built up over a number of years.