I have been working on a WordPress website that utilizes the contact form 7 plugin. My goal is to redirect the page to a thank you page while appending the form ID to the URL. However, I have encountered an issue where it keeps redirecting me to the home page instead of the desired thank you page. I am utilizing the wpcf7mailsent DOM event for this purpose.
Despite spending several hours searching for a solution, I have attempted various methods of redirection with no success:
window.location("/thankyou?submission="+formID);
document.location = 'https://example.com/thankyou'+formID;
document.location.href = '/thankyou?submission='+formID;
window.location.assign('https://example.com/thankyou'+formID);
window.location.replace('https://example.com/thankyou'+formID);
jQuery(location).attr('href','example.com/thankyou'+formID);
The following code snippet illustrates my current approach:
var nr_wpcf7Elm = document.querySelector( '.wpcf7' );
nr_wpcf7Elm.addEventListener( 'wpcf7mailsent', function( event ) {
var inputs = event.detail.inputs;
var formID = event.detail.contactFormId;
window.location.href = '/thankyou?submission='+formID;
}, false );
In conclusion, I am seeking assistance in successfully redirecting users to a thank you page while ensuring the inclusion of the form ID in the URL.