WORDPRESS : Solve problem with ” Contact form 7 “, “Additional Settings” update and WPML

September 18th, 2017

From some months, if you had set additional settings, on “additional settings” panel in ” Contact Form 7 ” , when you update the plugin, had an error:

This epends because the Javascript code for some of this additional settings is deprecated. ( if you don’t see any error notification , never mind, the actions you using aren’t deprecated ).

First of all remove the code in ” Additional Settings ” tab.
Second, open a file .js from your theme and paste this code ( in this example use code for redirect on thank you page after submit ).

if you have only one form:

 document.addEventListener( 'wpcf7mailsent', function( event ) {
            location = 'http://www.yourdomain.com/thankyou/';
        }, false );

If you want targeting a specific form:

document.addEventListener( 'wpcf7mailsent', function( event ) {
    if ( '123' == event.detail.contactFormId ) {
        ga( 'send', 'event', 'Contact Form', 'submit' );
}, false );

If you have a simple form , without multi language ( in my case language are managed with WPML )That’s all.

If you try your form, you can see that work’s fine ( as before ).

If you use “WPML”, there’s something more to do.

Open your function.php, and paste this code :

add_filter('body_class', 'append_language_class');
function append_language_class($classes){
  $classes[] = ICL_LANGUAGE_CODE;  //or however you want to name your class based on the language code
  return $classes;

This snippet add to body a class with the actual language code ( es: en, it, fr, ecc ), from now, we can use this class for check ( by jquery ) in whic language we are.
Now we must change a little bit our jQuery script:

 if (jQuery("body").hasClass("it")) {
        document.addEventListener( 'wpcf7mailsent', function( event ) {
            location = 'http://www.yourdomain.com/grazie/';
        }, false );
    if (jQuery("body").hasClass("en")) {
        document.addEventListener( 'wpcf7mailsent', function( event ) {
            location = 'http://www.yourdomain.com/en/thankyou/';
        }, false );

With this method you can add different thank you page for different language.

That’s all

Comments are closed.