Contact Form 7 with reCaptcha

You may find that the reCaptcha feature offered in Contact Form 7 does not work if you have enabled desktop theme shortcode support in WPtouch Pro.


This is due to a timing conflict with Contact Form 7 and our desktop shortcode handling: Contact Form 7 keeps track of which modules have been used and only enqueues the necessary JavaScript for the active modules as the page renders the footer. When desktop theme shortcode handling is on,  the output is cached to reduce server load and improve visitor experience – this interrupts the module detection and Contact Form 7 no longer knows to enqueue the JavaScript.


Correcting this is very simple. Simply paste the following into the Footer Content field in the mobile customizer:


 

<script type="text/javascript">
	var recaptchaCallback = function() {
		var forms = document.getElementsByTagName('form');
		var pattern = /(^|\\s)g-recaptcha(\\s|$)/;

		for (var i = 0; i < forms.length; i++) {
			var divs = forms[i].getElementsByTagName('div');

			for (var j = 0; j < divs.length; j++) {
				var sitekey = divs[j].getAttribute('data-sitekey');
				if (divs[j].className && divs[j].className.match(pattern) && sitekey) {
					grecaptcha.render(divs[j], {
						'sitekey': sitekey,
						'theme': divs[j].getAttribute('data-theme'),
						'type': divs[j].getAttribute('data-type'),
						'size': divs[j].getAttribute('data-size'),
						'tabindex': divs[j].getAttribute('data-tabindex'),
						'callback': divs[j].getAttribute('data-callback'),
						'expired-callback': divs[j].getAttribute('data-expired-callback')
					});

					break;
				}
			}
		}
	}
</script>
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?onload=recaptchaCallback&amp;render=explicit&amp;ver=2.0"></script>

 

Still need help? Contact Us Contact Us