Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; widget_embed has a deprecated constructor in /data/web/e36524/html/greenitsolutions/wp-content/themes/jarvis_wp/includes/widgets/embed.php on line 3

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; widget_flickr has a deprecated constructor in /data/web/e36524/html/greenitsolutions/wp-content/themes/jarvis_wp/includes/widgets/flickr.php on line 3

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Tweets_Widget has a deprecated constructor in /data/web/e36524/html/greenitsolutions/wp-content/themes/jarvis_wp/includes/widgets/twitter.php on line 9

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; widget_portfolio has a deprecated constructor in /data/web/e36524/html/greenitsolutions/wp-content/themes/jarvis_wp/includes/widgets/portfolio.php on line 3
How to use multiple google recaptcha on same page

How to use multiple google recaptcha on same page

Actually I’m using Mailster for WordPress to collect subscriptions on Chatcloud.

To fight against spam subscriptions I’m using double opt-in for email verification and Google Recaptcha Version 3.

But there was one problem. The problem why you are reading this! Only one recaptcha field got the callback from google and all other forms showed and error „Please proof that you are human“.

Multiple Google Captchas on one site is not quite easy and this stackoverflow-thread didn’t help me much.

Old code

Fills in the callback token in a form field with a specific id.

grecaptcha.ready(function() {
	grecaptcha.execute('YOUR ID', {
		action : 'mailster_form_3_submit'
	}).then(function(token) {
		document.getElementById('mailster-_recaptcha-3-5d1b9cc5dcf84').value = token;
	});
}); 

New code for multiple fields

Fills in the callback token in all form fields with a specific name.

jQuery(document).ready(function() {

	grecaptcha.ready(function() {
		grecaptcha.execute('YOUR ID', {
			action : 'mailster_form_submit'
		}).then(function(token) {
			responseInputs = document.getElementsByName('g-recaptcha-response');
			
			for (var x = 0; x < responseInputs.length; x++) {
				responseInputs[x].value = token;
			}
		});
	});
}); 

Be shure to render this code under the generic mailster js code. Maybe before the closing </body> tag.

Sei sozial und teile

Über den Autor Andreas Grundner

Ich arbeite als Wordpress-, Joomla-, Typo3-, Magento-Integrator, Rootserver-Administrator und Webanwendungsprogrammierer. Meine Verpflichtung gilt dem Datenschutz, meine Leidenschaft dem Finden und Aufzeigen von Sicherheitslücken in Webanwendungen.

Meinung sagen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.