Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Issue #512, Multiple captchas attempted fix
In addition to previous commit, I realized that the Google validation
callback needed to identify which form so it wouldn't mark both forms,
so I created an array of callback functions each with a reference to a
form ID (which is created if not already present). Fingers crossed this
won't blow anything up!
For @jeesus to test with.
  • Loading branch information
FuzzyBS committed Oct 17, 2016
commit cb8ee6050e3f608269f21cb5580fc6daa0279fed
17 changes: 12 additions & 5 deletions src/modules/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,12 @@
$forms = $('form');
}

var i=0,
grecaptchaRenderCallback = [];
$forms.each(function () {
var $form = $(this),
config = $form.context.validationConfig || false;
if (config) {
if (config) {

$('[data-validation~="recaptcha"]', $form).each(function () {
var $input = $(this),
Expand All @@ -570,21 +572,26 @@
throw new Error('Google reCaptcha site key is required.');
}

var grecaptchaRenderCallback = function (result) {
$('form').each(function () {
if (!$form.attr('id')) {
$form.attr('id', 'recaptcha-form-' + (i++));
};
grecaptchaRenderCallback[$form.attr('id')] = function (result) {
var formID;
$('#' + formID).each(function () {
$('[data-validation~="recaptcha"]', $(this)).each(function () {
$(this).trigger('validation', (result && result !== ''));
});
});
};
grecaptchaRenderCallback[$form.attr('id')].formID = $form.attr('id');

var widgetId = grecaptcha.render(div, {
sitekey: siteKey,
theme: theme,
size: size,
type: type,
callback: grecaptchaRenderCallback,
'expired-callback': grecaptchaRenderCallback
callback: grecaptchaRenderCallback[$form.attr('id')],
'expired-callback': grecaptchaRenderCallback[$form.attr('id')]
});

$input
Expand Down