Menu Close

Contact form 7 plugin redirected to a URL after submission

After you have submitted your contact form 7. It remains on the same page but a message will come out.

In some situation, you need to redirect your contact form 7 to a different URL after the visitor click submission button. How can you do that ?

The simplest way is utilizing Contact Form 7’s custom DOM event to run JavaScript.

The following is an example of script that redirects you to another URL when the wpcf7mailsent event occurs:

<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
    location = 'https://foods2young.com/';
}, false );
</script>

Embed this snippet into your theme’s template file. Obviously, you need to replace the https://foods2young.com/ in the code to the URL you want to redirect to.

Normally what I can do is to download and install “Insert Headers and Footers” plugin, and copy and past the above code into the insert “Scripts in Header” line.

 

List of Contact Form 7 custom DOM events

  • wpcf7invalid — Fires when an Ajax form submission has completed successfully, but mail hasn’t been sent because there are fields with invalid input.
  • wpcf7spam — Fires when an Ajax form submission has completed successfully, but mail hasn’t been sent because a possible spam activity has been detected.
  • wpcf7mailsent — Fires when an Ajax form submission has completed successfully, and mail has been sent.
  • wpcf7mailfailed — Fires when an Ajax form submission has completed successfully, but it has failed in sending mail.
  • wpcf7submit — Fires when an Ajax form submission has completed successfully, regardless of other incidents.

Related Posts

Leave a Reply