idk
idk

Reputation: 113

Contact Form 7 : Not routing to new page

I am using Contact Form 7 and JS to load a new page upon successful form submission. However, upon the submission of the contact form, I am routed to the following url: https://example.com/#wpcf7-f95-p2-o1

My inline JS is as follows:

document.addEventListener( 'wpcf7mailsent', function( event ) {
    alert("The form has been sent");
    location = 'http://www.example.com/thank-you/';
}, false );

However, this redirect (to url/#wpcf7-f95-p2-o1) occurs on all browsers and devices, and the alert message never populates. There are no console errors or warnings pertaining to this script - which leads me to believe that this script is never being triggered.

Is there something that I could have done in order to prevent this function from opperating?

Upvotes: 1

Views: 58

Answers (1)

Mason
Mason

Reputation: 779

Try adding this code to functions.php:

add_filter('wpcf7_form_action_url', 'remove_unit_tag');

function remove_unit_tag($url){
    $remove_unit_tag = explode('#',$url);
    $new_url = $remove_unit_tag[0];
    return $new_url;
}

this will remove the tag, also for redirecting, you can use something like this which gives more options

Upvotes: 0

Related Questions