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

40395 Multiple forms with reCAPTCHA lead to wrong submission #648

Merged
Merged
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
2 changes: 1 addition & 1 deletion css/onoffice-forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ span.onoffice-pleasefill {
margin-right: 5pt;
}

.onoffice-unclickable-form
.onoffice-unclickable-form,
.oo-form input[type=submit]:disabled,
#onoffice-form input[type=submit]:disabled {
opacity: 0.5;
Expand Down
2 changes: 1 addition & 1 deletion dist/onoffice-prevent-double-form-submission.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions js/onoffice-prevent-double-form-submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ jQuery(document).ready(function ($) {

if ($(submitButton).is(':visible')) {
submitButton.on('click', function () {
if (formElement.checkValidity()) {
submitButton.prop('disabled', true);
submitButton.addClass('onoffice-unclickable-form');
}
submitButton.prop('disabled', true);
submitButton.addClass('onoffice-unclickable-form');
});
}
});
Expand Down
2 changes: 2 additions & 0 deletions templates.dist/form/applicantform.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
echo '<p>'.esc_html__('ERROR!', 'onoffice-for-wp-websites').'</p>';
} elseif ($pForm->getFormStatus() === \onOffice\WPlugin\FormPost::MESSAGE_REQUIRED_FIELDS_MISSING) {
echo '<p>'.esc_html__('Missing Fields!', 'onoffice-for-wp-websites').'</p>';
} elseif ($pForm->getFormStatus() === onOffice\WPlugin\FormPost::MESSAGE_RECAPTCHA_SPAM) {
echo '<p>'.esc_html__('Spam detected!', 'onoffice-for-wp-websites').'</p>';
}

/* @var $pForm \onOffice\WPlugin\Form */
Expand Down
2 changes: 2 additions & 0 deletions templates.dist/form/applicantsearchform.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

if ($pForm->getFormStatus() === onOffice\WPlugin\FormPost::MESSAGE_ERROR) {
echo esc_html__('ERROR!', 'onoffice-for-wp-websites');
} elseif ($pForm->getFormStatus() === onOffice\WPlugin\FormPost::MESSAGE_RECAPTCHA_SPAM) {
echo esc_html__('Spam detected!', 'onoffice-for-wp-websites');
}

/* @var $pForm \onOffice\WPlugin\Form */
Expand Down
41 changes: 23 additions & 18 deletions templates.dist/form/formsubmit.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,34 @@
/** @var \onOffice\WPlugin\Form $pForm */
if ($pForm->needsReCaptcha() && $key !== '') {
$formId = $pForm->getGenericSetting('formId');
$pFormNo = $pForm->getFormNo();
?>
<script>
function onSubmit() {
var element = document.getElementById(<?php echo json_encode($formId); ?>);
element.submit();
var submited = false;
function submitForm<?php echo $pFormNo; ?>() {
if (submited) {
return;
}
const formNo = <?php echo $pFormNo; ?>;
const selectorFormById = `form[id="onoffice-form"] input[name="oo_formno"][value="${formNo}"]`;
const form = document.querySelector(selectorFormById).parentElement;
submited = true;
form.submit();
}
function submit<?php echo $pFormNo; ?>() {
const formNo = <?php echo $pFormNo; ?>;
const selectorFormById = `form[id="onoffice-form"] input[name="oo_formno"][value="${formNo}"]`;
const form = document.querySelector(selectorFormById).parentElement;
const submitButtonElement = form.querySelector('.submit_button');
onOffice.captchaControl(form, submitButtonElement);
}
</script>

<div id='recaptcha' class="g-recaptcha"
data-sitekey="<?php echo esc_attr($key); ?>"
data-callback="onSubmit"
data-size="invisible"></div>
<button class="submit_button"><?php echo esc_html($pForm->getGenericSetting('submitButtonLabel')); ?></button>
<script>
(function() {
var formId = <?php echo json_encode($formId); ?>;
var formElement = document.getElementById(formId);
var submitButtonElement = formElement.getElementsByClassName('submit_button')[0];
onOffice.captchaControl(formElement, submitButtonElement);
})();


</script>
<button class="submit_button g-recaptcha" data-sitekey="<?php echo esc_attr($key); ?>"
data-callback="submitForm<?php echo $pFormNo; ?>" data-size="invisible"
onClick="submit<?php echo $pFormNo; ?>">
<?php echo esc_html($pForm->getGenericSetting('submitButtonLabel')); ?>
</button>
<?php
} else {
?>
Expand Down
2 changes: 2 additions & 0 deletions templates.dist/form/ownerform.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
} else {
if ($pForm->getFormStatus() === \onOffice\WPlugin\FormPost::MESSAGE_ERROR) {
echo esc_html__('ERROR!', 'onoffice-for-wp-websites');
} elseif ($pForm->getFormStatus() === onOffice\WPlugin\FormPost::MESSAGE_RECAPTCHA_SPAM) {
echo esc_html__('Spam detected!', 'onoffice-for-wp-websites');
}

/* @var $pForm \onOffice\WPlugin\Form */
Expand Down
Loading