Search code examples
javascriptphpjquerywordpresscontact-form-7

How to change captcha error language from Contact form 7 google recaptcha?


How can we change captcha error message if not checked in Contact form 7?

Please verify that you are not a robot.

I'm using C7's default Google captcha integration method. Is there any method to filter these messages without editing plug in files?

One site having English and French translations using Ceceppa Multilingua and other site only for French.


Solution

  • After continuous research, I got a solution.

    <?php $err_mg = (get_lang() === 'en') ? "Sorry, captcha not solved. Please try again." : "S\'il vous plaît vérifier l\' Captche."; ?>
    
        jQuery(document).ready(function(){
            jQuery('.wpcf7').on('.wpcf7:spam', function(event){
              jQuery('.wpcf7-recaptcha').append('<span class="captcha-error"><?=$err_mg?></span>');
              jQuery('.captcha-error').css('color','red');
              setTimeout(function(){ 
                jQuery('.captcha-error').remove();
              }, 5000);
            });
        });
    

    There is are new custom events using for contact form 7.

    New jQuery custom event triggers

     - wpcf7:invalid 
     - wpcf7:spam 
     - wpcf7:mailsent 
     - wpcf7:mailfailed 
     - wpcf7:submit