简体   繁体   中英

contact form 7 and contact form 7 success page redirect plugin conflicts

I have implemented these two plugins:

  • contact form 7, and
  • contact form 7 success page redirect.

These plugins been conflicts.

Firstly, the client side validation is not working.

Secondly, on success it is not redirecting to success page.

If you just want to redirect users upon successful message then better approach would be to use javascript hook.

Remove the success page redirect plugin.

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

just go to Additional Settings tab in contact form 7 and paste this without any leading spaces, replace your success page url with the example.com.

To work on client side validation, please put these lines in footer.php

<script type='text/javascript' src='/wp-content/plugins/contact-form-7/includes/js/scripts.js?ver=3.5.2'></script>



<script type='text/javascript' src='/wp-content/plugins/contact-form-7/includes/js/jquery.form.min.js?ver=3.40.0-2013.08.13'></script>



<script type='text/javascript'>

please copy syntax at your own this is cdata .>var _wpcf7 = {"loaderUrl":"/wp-content/plugins/contact-form-7/images/ajax-loader.gif","sending":"Sending ..."}; ]]>

now in your cf7-success-page-redirects.php that is in plugin directory .

change this function

function cf7_success_page_form_submitted( $contact_form ) {
$contact_form_id = $contact_form->id();

// Send us to a success page, if there is one
$success_page = get_post_meta( $contact_form_id, '_cf7_success_page_key', true );
if ( !empty($success_page) ) {
    $items = array();
    $items['mailSent'] = true;
    $items['redirectLink'] =get_permalink( $success_page );
    echo wp_json_encode( $items );
    die();
}

}

now in your contact form 7 directory of plugin find js folder , and look for script.php and replace this bunch of code.

else if (1 == data.mailSent) {
        $responseOutput.addClass('wpcf7-mail-sent-ok');
        $form.addClass('sent');

        if (data.onSentOk) {
            $.each(data.onSentOk, function(i, n) { eval(n) });
        }

        $(data.into).trigger('wpcf7:mailsent');
        $(data.into).trigger('mailsent.wpcf7'); // deprecated
        location.assign(data.redirectLink);



    } 

i have fixed this on my website for client hope this will help someone in future.

Use below code in functions.php (located in themes -> themeName Folder).

Put this in the end of file.

add_action( 'wp_footer', 'mycustom_wp_footer' );

function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( e ) {
    var str = window.location.href;
    if( str.includes("flp") ){
        window.location.href = "http://www.WebsiteName.com/facebook-thank-you";
    } else if( str.includes("glp") ){
        window.location.href = "http://www.WebsiteName.com/google-thank-you";
    }
}, false );
</script>
<?php
}

Working Perfectly..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM