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

Multiple forms with reCAPTCHA lead to wrong submission #631

Closed
fredericalpers opened this issue Sep 18, 2023 · 6 comments · Fixed by #648
Closed

Multiple forms with reCAPTCHA lead to wrong submission #631

fredericalpers opened this issue Sep 18, 2023 · 6 comments · Fixed by #648
Assignees
Labels
QA Issue or Pull request that is in review
Milestone

Comments

@fredericalpers
Copy link
Member

Current state

Multiple forms on one page with reCAPTCHA cause that when submitting a completed form, empty fields of another form are flagged.

Desired state

If several forms on a page are protected with reCAPTCHA, they should be able to be submitted properly.

Possible Solution

The form number must be added to e.g. defaultform.php
<form method="post" id="onoffice-form-<?php echo $pForm->getFormNo(); ?>">

and at the end the formsubmit.php will be loaded
include(__DIR__.'/formsubmit.php');

Example of the new formsubmit.php:


/**
 *
 *    Copyright (C) 2018  onOffice GmbH
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

$key = get_option('onoffice-settings-captcha-sitekey', '');
/** @var \onOffice\WPlugin\Form $pForm */
if ($pForm->needsReCaptcha() && $key !== '') {
	$formId = $pForm->getGenericSetting('formId');
?>
	<script>
		function submitForm<?php echo $pForm->getFormNo(); ?>() {
			var form = document.getElementById("onoffice-form-<?php echo $pForm->getFormNo(); ?>");
			var isValid = form.checkValidity();
			if (isValid) {
				form.submit();
			} else {
				form.reportValidity();
			}
		}
	</script>

	<button class="submit_button g-recaptcha" data-sitekey="<?php echo esc_attr($key); ?>" data-callback="submitForm<?php echo $pForm->getFormNo(); ?>" data-size="invisible"><?php echo esc_html($pForm->getGenericSetting('submitButtonLabel')); ?></button>
<?php
} else {
?>

	<input type="submit" value="<?php echo esc_html($pForm->getGenericSetting('submitButtonLabel')); ?>">

<?php
}```
@fredericalpers fredericalpers added bug Indicates an unexpected problem or unintended behaviour 1 week labels Sep 18, 2023
@fredericalpers fredericalpers modified the milestones: v4.18, v4.17 Sep 18, 2023
@yeneastgate
Copy link
Contributor

@fredericalpers I need 3 days to fix and test it. Thanks!

@yeneastgate
Copy link
Contributor

yeneastgate commented Sep 25, 2023

@fredericalpers

The form number must be added to e.g. defaultform.php
<form method="post" id="onoffice-form-<?php echo $pForm->getFormNo(); ?>">

This solution will impact backward compatibility If User use "id=onoffice-form" customize in template..

I found an alternative solution that we can select according by the "oo_formno" value in the form.
image

Do you agree with my solutions?

Note: Now, I saw "spam detected!" notification only show in the contact form.
Do you want to add a notification for the "owner form" or "interest form"?

@fredericalpers
Copy link
Member Author

@yeneastgate Please go ahead and implement your suggested solution for backwards compatibility. :)

The "Spam detected" notification should be displayed in all forms that are protected by reCAPTCHA.

@dai-eastgate
Copy link
Contributor

@fredericalpers I fixed this bug and added a "Spam detected" notification in all forms that are protected by reCAPTCHA. Please take a look at my video demo and let me know your opinions. Thanks!
https://files.fm/u/2x6cc7yfby

@fredericalpers
Copy link
Member Author

@dai-eastgate seems good to me! thank you :) can I label it as "in review"?

@dai-eastgate
Copy link
Contributor

@dai-eastgate seems good to me! thank you :) can I label it as "in review"?

Yes, please review this PRs for me. ^^

@fredericalpers fredericalpers added QA Issue or Pull request that is in review and removed bug Indicates an unexpected problem or unintended behaviour 1 week labels Oct 4, 2023
@yeneastgate yeneastgate self-assigned this Oct 25, 2023
@fredericalpers fredericalpers modified the milestones: v4.17, v4.15.1 Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QA Issue or Pull request that is in review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants