Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contact Form 7 redirect after submission

I'm using contact form 7 and I'm trying to redirect to another page after a successful contact form submission.

I've tried using Contact Form 7 – Success Page Redirects (https://nl-be.wordpress.org/plugins/contact-form-7-success-page-redirects/) but the plugin isn't compatible with the theme and gives some errors.

Is there another way to redirect without using that plugin? I've found this https://contactform7.com/redirecting-to-another-url-after-submissions/ too, but I'm not able to implement it. The redirection is also only necessary for one contact form on the site, not all of them.

Thank you!

J.

like image 337
YDAJerVa Avatar asked Apr 30 '17 14:04

YDAJerVa


People also ask

How do I redirect a form after submission?

If you want to redirect to another page after form submit html, Then you have to provide/Sign the Other pages path inside HTML Form tag's ACTION Attribute. Which will POST/Send your Form data to that Location and Open/Redirect your Users to That Given Web Page.

How do I redirect a wordpress form after submitting?

To do this, go to Settings » Confirmation like before. This time, select Go to URL (Redirect) from the Confirmation Type dropdown menu. Then, paste the complete URL of the external page you'd like to send the user to in the field labeled Confirmation Redirect URL.


2 Answers

I've seen quite a few answers with the same responses. The major question comes when you have 10 forms and 10 different thank you pages and this solution won't work.

I have a workaround for this.

Step 1: Create a hidden field in your form and add the thank you page URL in that.

[hidden thankyouURL id:thankyouURL default:http://example.com/thank-you/ "http://example.com/thank-you/"]

Step 2: In the DOM event, get the thank you URL from the field and redirect the user.

<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
    var thankyouURL = document.getElementById("thankyouURL").value;
    location = thankyouURL;
}, false );
</script>

That's it.

like image 107
Harish Kotra Avatar answered Nov 15 '22 05:11

Harish Kotra


I'm trying to do the same thing but yet no success. the on_sent_ok is about to be no longer recommended. Check this page DOM EVENTS on the end of the page you can find the code for a specific form.

like image 34
Pedro Gelli Avatar answered Nov 15 '22 06:11

Pedro Gelli