Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/da 1573 merge #5

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function getRecaptchaScript()

$query = array(
'onload' => 'recaptchaOnloadCallback',
'render' => 'explicit',
'render' => $this->getSiteKey(),
'hl' => $lang
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,28 @@ $submitMethod = $this->getSubmitMethod() ? $this->getSubmitMethod() : 'form.subm
var form = <?php echo $formHandle ?>;
jQuery(form.form).one('click.captcha hover.captcha focus.captcha', function(){
jQuery(this).off('.captcha');
var widgetId = grecaptcha.render(container, {
'theme': "<?php echo $this->getTheme(); ?>",
'type': "<?php echo $this->getType(); ?>",
'badge': "<?php echo $this->getBadgeLocation(); ?>",
'error-callback': function() {
recaptchaShowErrorAndRetry('<?php echo $id ?>', widgetId);
},
'callback': function(response) {
if (form.validator && form.validator.validate()){
console.log('reCaptcha ('+widgetId+') passsed and form is valid');
<?= $submitMethod; ?>;
} else {
console.log('reCaptcha ('+widgetId+') passsed but form not valid, resetting');
grecaptcha.reset(widgetId);
}
}
});
console.log('reCaptcha widget '+widgetId+' rendered');
jQuery(container).attr('data-widget-id', widgetId);
$(form.form).on('submit', function (e) {
e.preventDefault();

// Stop normal form submission, so we can trigger validation and the recaptcha challenge in the
// correct order. Actual form submission is done in the recaptcha callback that we specified in
// the grecaptcha.render() call.
jQuery(form.form).submit(function (event) {
if (form.validator.validate()) {
grecaptcha.execute(widgetId);
event.preventDefault();
}
grecaptcha.ready(function() {
grecaptcha.execute("<?php echo $this->getSiteKey(); ?>", {action: 'submit'}).then(function(token) {
console.log('grecaptcha.ready');
var form = <?php echo $formHandle ?>;
if (form.validator && form.validator.validate()) {
console.log('reCaptcha passsed and form is valid');
jQuery('<input>', {
type: 'hidden',
id: 'g-recaptcha-response',
name: 'g-recaptcha-response',
value: token
}).appendTo(jQuery('#recaptcha-<?php echo $id ?>').closest('form')[0]);
form.submit();
} else {
console.log('reCaptcha passsed but form not valid, resetting');
//grecaptcha.reset();
}
});
});
});
});

Expand Down