Search code examples
javascriptjquerywordpresscontact-formcontact-form-7

Contact Form 7 not redirecting upon email sent


I have a form that I am trying to have redirect to http://www.example.com upon successfully sending an email. I have tried different approaches including on_sent_ok in the additional settings as well as

if(jQuery('.wpcf7-mail-sent-ok').length > 0)   
window.location.replace("http://stackoverflow.com");

in my JavaScript, but that does not seem to work as well.

Edit: I forgot to mention that upon the user clicking submit, I do a prevent default in order to do some calculations and generate a PDF. Once it is all done I do

$("form.wpcf7-form").unbind('submit').submit(); 

to allow the submission to happen. Could this be causing any issues with the redirection?


Solution

  • Contact Form 7 made a ajax call. After success the element is inserted. Then you can check if element exist:

    jQuery(document).ajaxComplete(function() {
      if (jQuery('.wpcf7-mail-sent-ok').length) {
        alert(1);
       //window.location.replace("http://stackoverflow.com");
      }
    });