Add recaptcha only to the last step of a wizard

Created on 14 April 2021, almost 4 years ago
Updated 21 April 2023, almost 2 years ago

Problem/Motivation

1. multi-step webform shows/requires recaptcha on every page...
2. ...but it fails validating starting the second step

the following error shows up:
"There was an error during validation of your form submission, please try to reload the page and submit form again."

reason seems to be that the the token is already set on JS end, so AJAX submit is not prevented
but the simple_recaptcha_message is missing from the form state

Steps to reproduce

Create a webform with multiple wizard pages.
Add the recaptcha handler.
Try to fill the form as a visitor
- you will get recaptcha on every step.
- on the second step it will fail with generic error.

Proposed resolution

Workaround and UX improvement: only add recaptcha to the last step of the form.
(or maybe adding to the first step only would make more sense?)

Remaining tasks

Create a patch.

User interface changes

None

API changes

None.

Data model changes

None.

โœจ Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

๐Ÿ‡ท๐Ÿ‡ดRomania reszli Tรขrgu Mureศ™

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium gilles_webstanz

    Hello,

    I think we can close this issue because when you update to the last version webform & simple google recaptcha it works fine.

    Have a nice day.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia mohit_aghera Rajkot

    I'm using patch #3 in webform 6.1.4
    It works fine.
    Attaching patch with more restrictions as I noticed following errors while indexing the content.
    TypeError: array_keys(): Argument #1 ($array) must be of type array, null given in array_keys() (line 142

    So doing extra check to ensure that `$pages` is array will not trigger the error.
    Keeping in needs work until we have consensus around whether we need to close it or keep it active.

  • ๐Ÿ‡ต๐Ÿ‡ฑPoland sandboxpl Poland ๐Ÿ‡ต๐Ÿ‡ฑ

    when testing this we can see that recaptcha logic is attached to the last page of wizard as expected, yet when webform has ajax enabled it indeed has a problem. On the last page of wizard, when we have previous/next buttons available, the "previous" one does not work anymore, this is probably caused by following checks:
    https://git.drupalcode.org/project/simple_recaptcha/-/blob/8.x-1.x/js/si...
    https://git.drupalcode.org/project/simple_recaptcha/-/blob/8.x-1.x/js/si...
    Since this check will pass for both buttons it will break the ajax on previous button, I think we need to try to validate if element triggering ajax is really a submit button , since there is buttons.js which tries to mark exactly one file with .simple-recaptcha-submit class, maybe it could be reused in ajax logic as well.

    Then this patch also raises a discussion if the recaptcha logic should be attached to first or last step of wizard ( imo first is better, since it can prevent creation of empty submissions by bots ), maybe to solve this we could extend handler settings and allow to choose if recaptcha should be added for first or last step on a webform basis..

  • First commit to issue fork.
  • ๐Ÿ‡ต๐Ÿ‡นPortugal fmfpereira
  • Pipeline finished with Success
    3 months ago
    Total: 659s
    #395984
  • ๐Ÿ‡ต๐Ÿ‡นPortugal fmfpereira

    Based on the feedback of #11 I've picked up on the patch from #10 and

    • Made sure that submit element that triggers the captcha contains the class .simple-recaptcha-submit
    • Add a configuration and logic to the webform handler to define if the submit element on the multistep form is triggered on the first or last step

    Changes were added to the issue fork.

    Patch attached if needed.

  • Pipeline finished with Success
    3 months ago
    Total: 222s
    #396152
  • ๐Ÿ‡ต๐Ÿ‡นPortugal fmfpereira

    Adding a new version of the patch, since the last one missed an array validation of the first step.

    Issue fork branch is updated.

Production build 0.71.5 2024