Problem/Motivation

Reloading an image captcha triggers a JS error resulting in the user being redirected to JSON.

Steps to reproduce

  1. Load a page showing an image captcha.
  2. Click the reload icon below the captcha to regenerate the image.

Expected result

Captcha image replaced with new version via AJAX.

Actual result

JS error "Uncaught ReferenceError: FALSE is not defined" and subsequent redirect to JSON.

Uncaught ReferenceError: FALSE is not defined
    at HTMLAnchorElement.<anonymous> (image_captcha_refresh.js?v=10.4.1:47:9)
    at HTMLAnchorElement.dispatch (jquery.min.js?v=3.7.1:2:40035)
    at v.handle (jquery.min.js?v=3.7.1:2:38006)
(anonymous) @ image_captcha_refresh.js?v=10.4.1:47
dispatch @ jquery.min.js?v=3.7.1:2
v.handle @ jquery.min.js?v=3.7.1:2Understand this errorAI

Proposed resolution

Fix the JS error by replacing FALSE with false.

Remaining tasks

Commit.

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

n/a

Original report

hi.
drupal 10.3.8
php 8.3.6
update captcha to 2.0.7
erro in capcha reload and show this message ;

{"status":1,"message":"","data":{"url":"\/image-captcha-generate\/19\/1732275322","token":"37NDuQbGZHTvQyC9u3_RdHaRgyBZoyS8jCne2WjmQ6I","sid":"19"}}

CommentFileSizeAuthor
#14 image_captcha_refresh-3489166-14.patch389 bytestamnv

Issue fork captcha-3489166

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bolaghi created an issue. See original summary.

arunsahijpal’s picture

Hi @bolaghi,
I've tested it on
drupal 10.3.9
php 8.3.14
captcha 2.0.7

and it does not show any error.

jordik’s picture

Same error as in the description.
drupal 10.3.10
captcha 2.0.7

Reverting to captcha 2.0.6. makes the error disappear and captcha refreshes as expected.

jordik’s picture

The image_captcha_refresh.js was changed in 2.0.7 to return "FALSE" instead of "false" which causes a JSON error (can only handle lowercase booleans).
Changing it back to "false" resolves the issue.
MR created.

jordik’s picture

Status: Active » Needs review
jordik’s picture

Title: image captcha reload » Image captcha reload produces a JSON error
bolaghi’s picture

thank you @jordik , #5 Fixed the problem.

7r3y’s picture

Hi,

Drupal 11.0.9
PHP 8.3.6
Captcha 2.0.7

The problem still exists even after I changed FALSE to false in the image_captcha_refresh.js file as described in #5.

Update: I tried with dev version of module but the result is still the same.

suraj_vantagode’s picture

Hi,

Facing the same issue with the below versions:
Drupal 10.3.8
PHP 8.1.31
Captcha 2.0.6

The image_captcha_refresh.js is already set as "false", but I am still facing an issue.

jordik’s picture

Try rebuilding the cache and then refreshing the page.

shasha821110’s picture

the change from 'FALSE' to 'false' works for me. Thanks.

quilx’s picture

The error mentioned in #4 is more than obvious. The file image_captcha_refresh.js is a Javascript file and in javascript FALSE is not a boolean literal. The error is confirmed also by web browsers. The Javascript engine throws the following exception that can be seen in the Console when it encounters FALSE:

Uncaught ReferenceError: FALSE is not defined
    at HTMLAnchorElement.<anonymous> (image_captcha_refresh.js?v=10.4.1:47:9)
    at HTMLAnchorElement.dispatch (jquery.min.js?v=3.7.1:2:40035)
    at v.handle (jquery.min.js?v=3.7.1:2:38006)
(anonymous) @ image_captcha_refresh.js?v=10.4.1:47
dispatch @ jquery.min.js?v=3.7.1:2
v.handle @ jquery.min.js?v=3.7.1:2Understand this errorAI

By changing FALSE to false the problem is solved.

If you make this change then reload the page with "CTRL + SHIFT + R" in order to load the changed version and not the version cached by your browser.

tamnv’s picture

StatusFileSize
new389 bytes

Hi

I created a patch for changing from FALSE to false which work well from our side

cgrouge’s picture

Confirming the patch in #14 changing FALSE to false fixes the error for me.

Drupal 10.3.9
Captcha 2.0.7

7r3y’s picture

Re: #11

After rebuilding the cache and refreshing the page, the issue has indeed been resolved. Thank you!

feyp’s picture

Version: 2.0.7 » 2.x-dev
Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Updated IS. Code in the MR looks good to me and fixes the problem. Alternatively, #14 provides the changes from the MR as a patch file. The MR pipeline has warnings, but it looks like those were not newly introduced by the suggested changes. We already have a bunch of users in previous comments confirming this approach fixes the error for them. I'm going to go ahead an RTBC this.

anybody’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, good fix! Indeed in JS it should be lowercase!

  • anybody committed 03242dca on 2.x authored by jordik
    Issue #3489166 by jordik, feyp: Image captcha reload produces a JSON...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.