Osch aka Otto Schade

var formsToProtectOnPage = []; var currentForm; var currentValidationForm; var onSubmit = function (token) { if (currentValidationForm && currentValidationForm.validator && currentValidationForm.validator.validate() ) { currentForm.querySelector('[name="amasty_invisible_token"]').setAttribute('value', token); currentForm.submit(); } else { grecaptcha.reset(); } }; formsToProtect = ["form[action*=\"review\/product\/post\"]"]; formsToProtect.forEach(function (item) { formToProtect = $$(item)[0]; if (formToProtect) { formsToProtectOnPage.push(formToProtect); } }); for (var index in formsToProtectOnPage) { if (formsToProtectOnPage.hasOwnProperty(index)) { var formToProtectOnPage = formsToProtectOnPage[index]; if ('form' !== formToProtectOnPage.tagName.toLowerCase()) { formToProtectOnPage = formToProtectOnPage.getElementsByTagName('form'); if (0 < formToProtectOnPage.length) { formToProtectOnPage = formToProtectOnPage[0]; } else { continue; } } var recaptchaBlock = document.createElement('div'); recaptchaBlock.className = 'amasty_recaptcha'; formToProtectOnPage.appendChild(recaptchaBlock); var tokenInput = document.createElement('input'); tokenInput.type = 'hidden'; tokenInput.name = 'amasty_invisible_token'; tokenInput.value = ''; formToProtectOnPage.appendChild(tokenInput); formToProtectOnPage.onsubmit = function submitProtectedForm(event) { currentForm = event.target; currentValidationForm = new VarienForm(currentForm.id, false); recaptchaBlock = currentForm.querySelector(".amasty_recaptcha"); if ('' == recaptchaBlock.innerHTML) { recaptcha = grecaptcha.render(recaptchaBlock, { 'sitekey': '6LewT0AUAAAAAMnqZ66kQABAomBULLfi84dlcSIt', 'callback': onSubmit, 'size': "invisible", 'badge': 'bottomleft' }); } grecaptcha.reset(recaptcha); grecaptcha.execute(recaptcha); return false; } } }