Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
support same model forms on one page (issue #61)
Browse files Browse the repository at this point in the history
  • Loading branch information
himiklab committed Feb 9, 2018
1 parent 9fb048a commit 7f40838
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions ReCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,23 @@ public function run()
if (reCaptcha.data("recaptcha-client-id") === undefined) {
var recaptchaClientId = grecaptcha.render(reCaptcha.attr("id"), {
"callback": function(response) {
jQuery("#" + reCaptcha.attr("input-id")).val(response).trigger("change");
if (reCaptcha.attr("form-id") !== "") {
jQuery("#" + reCaptcha.attr("input-id"), "#" + reCaptcha.attr("form-id")).val(response).trigger("change");
} else {
jQuery("#" + reCaptcha.attr("input-id")).val(response).trigger("change");
}
if (reCaptcha.attr("data-callback")) {
eval("(" + reCaptcha.attr("data-callback") + ")(response)");
}
},
"expired-callback": function() {
jQuery("#" + reCaptcha.attr("input-id")).val("");
if (reCaptcha.attr("form-id") !== "") {
jQuery("#" + reCaptcha.attr("input-id"), "#" + reCaptcha.attr("form-id")).val("");
} else {
jQuery("#" + reCaptcha.attr("input-id")).val("");
}
if (reCaptcha.attr("data-expired-callback")) {
eval("(" + reCaptcha.attr("data-expired-callback") + ")()");
}
Expand Down Expand Up @@ -228,7 +238,9 @@ protected function buildDivOptions()
$divOptions['class'] = "{$divOptions['class']} {$this->widgetOptions['class']}";
}
$divOptions['input-id'] = $this->getReCaptchaId();
$divOptions['id'] = $this->getReCaptchaId() . '-recaptcha';
$divOptions['form-id'] = isset($this->field->form->id) ? $this->field->form->id : '';
$divOptions['id'] = $this->getReCaptchaId() . '-recaptcha' .
($divOptions['form-id'] ? ('-' . $divOptions['form-id']) : '');

return $divOptions;
}
Expand Down

0 comments on commit 7f40838

Please sign in to comment.