onOffice-Web-Org / oo-wp-plugin

onOffice for WP-Websites
https://wp-plugin.onoffice.com
GNU General Public License v3.0
9 stars 9 forks source link

Multiple forms with reCAPTCHA lead to wrong submission #631

Closed fredericalpers closed 10 months ago

fredericalpers commented 11 months ago

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
}```
yeneastgate commented 11 months ago

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

yeneastgate commented 11 months ago

@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 commented 11 months ago

@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 commented 11 months ago

@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 commented 11 months ago

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

dai-eastgate commented 11 months ago

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

Yes, please review this PRs for me. ^^