Pergunta

I tried using the on_sent_ok to redirect after form submit for Contact Form 7 (Wordpress plugin), but it doesn't work for some reason:

on_sent_ok: "location.replace('http://www.company.com/thank-you/');"

Why wouldn't this work?

I am using CF7 versions 2.2.1 and Wordpress 3.5.0.

Foi útil?

Solução 3

on_sent_ok not working in Contact Form 7 normally indicates a Javascript conflict with either your current WordPress theme or one of the other plugins you are using - see Contact Form 7 Email Issues - there is a link there that covers Javascript Conflicts.

Remember that a problem in one script can cause issues in another. For example, some jQuery errors can stop jQuery processing any more script, which can make the culprit hard to find.

A jQuery error in one of your plugins or your themes javascript files can stop jQuery processing before it gets to the CF7 script.

Use Firebug or Chrome Dev Tools to examine Javascript conflicts in detail.

See http://wiki.simple-press.com/installation/troubleshooting/plugin-conflicts/ for general guidance.

Outras dicas

Contact Form 7 Thank You Page Redirects THE OLD METHOD: on_sent_ok hook is no longer recommended. I have a code you can copy and paste. You can add that method bottom of your functions.php file, add this code:

<pre>
<code>
add_action( 'wp_footer', 'mycustom_wp_footer' );

function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
   if ( '97' == event.detail.contactFormId ) { 
    location = 'http://www.vizistata.com/affordable-logo-designs.php';
    } 
    else if ( '634' == event.detail.contactFormId ) { // 634 is the form id
        location = 'http://www.vizistata.com/#blog';
    } 

    else if ( '635' == event.detail.contactFormId ) { // 635 is the form id
        location = 'http://www.vizistata.com/#contact';
    } 

    else if ( '636' == event.detail.contactFormId ) { 
        location = 'http://www.vizistata.com/#services';
    } 

    else if ( '94' == event.detail.contactFormId ) { 
        location = 'http://www.vizistata.com/#about';
    } 


    else { // Sends submissions on all unaccounted for forms to the third thank you page
        location = 'http://www.vizistata.com/';
    }
}, false );
</script>
<?php
}</pre>
</code>

Had the same problem with my own Wordpress theme. After an hour I understood that forgot to add <?php wp_footer(); ?> in footer.php, so important Contact 7 scripts doesn't load. When I add it everthing worked.

Try this...

on_sent_ok: "location = 'http://example.com/';"

in additional settings

I've tried both solutions: on_sent_ok didn't work and adding redirect javascript didn't do the job either. Eventually, I found myself editing the file 'submissions.php' inside the 'modules' folder of 'contact-form-7'. look for: private function submit() in there, look for elseif ( $this->mail() I've commented $this->response = $contact_form->message( 'mail_sent_ok' ); and just put header("Location: www.somesite.com/"); Works pretty well.

Contact form 7 Redirecting to Another URL After Submissions

First you need to update contact form 7 on new version i try it on v7.4.9 and then place a contact form short code in any page and place this JS script any where on page and change url where need to redirect your page after submission

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

For more info click contact form 7 official site https://contactform7.com/redirecting-to-another-url-after-submissions/

I faced same problem in contact form 7 latest version 4.8.1 .

finally solved issue using custom jquery code.

if ($('.wpcf7-form.sent').length) {
      $(location).attr('href', 'http://www.example.com')
    }

Note: Contact form 7 form successful submit adding class "sent" to form field .

I use the following code for this. I put it in one line to just save a few characters. If necessary, you can still work with is_page or something so that the JavaScript is only output for pages that also contain a form.

/* Inline script for redirect cf7 to thank you page */
// https://contactform7.com/redirecting-to-another-url-after-submissions/
add_action('wp_footer', 'cf7__redirect_thankyoupage');
function cf7__redirect_thankyoupage() {
    ?><script>document.addEventListener('wpcf7mailsent',function(event) {location='/thank-you';}, false );</script><?php
}

And if you are using WPML and only want to output it for one language, then you can use the following code:

if (null !== ICL_LANGUAGE_CODE && ICL_LANGUAGE_CODE == "en"){ ... }

It is best to set the thank you pages to Noindex (via Robots.txt / Meta).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top