Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
when i enable lightbox for contant page - CAPTCHA doesn't works on it, not showing ;(
Comments
Comment #1
AlexisWilke CreditAttribution: AlexisWilke commentedThe module uses a filter: lightbox2_filter_xss().That means all JavaScript is removed. What's funny is that this other function returns a script which gets removed too (ha! ha!):Okay! Strike that. 8-) The JavaScript is executed. However, the reCAPTCHA uses:
(1) drupal_add_js() and those entries are not taken in account. You need to add
print drupal_get_js();
to the lightbox2_contact() function (shown below).(2) But that's not enough because the reCAPTCHA also calls drupal_set_html_head() to add a JavaScript in the header. Rather surprising because the drupal_add_js() does what is required, and that can be caught in the file as required, but not if added in the header with the drupal_set_html_head() function.
Yet, at this point it still fails. So does the Message textarea which makes use of a JS to add the resize bar at the bottom of the window and that means the Message textarea does not even appear! (it's hidden by the JS)
So I finally had the idea to look at the JavaScript console because quite often that is why something breaks (i.e. as soon as a JS generates an error, all others are ignored and never executed!) Sure enough there was an error: #974736: "m.lang.contextmenu is undefined" error message.
I used the fix shown in #2 and it started working a lot better! But so far I still don't see the reCAPTCHA... still working on it.
Update: Okay! I got it! We my changes (
drupal_set_html_head() with drupal_add_js()
in reCAPTCHA andprint drupal_get_js();
,) I got this script entry:<script type="text/javascript" src="/https://www.google.com/recaptcha/api/js/recaptcha_ajax.js?b"></script>
which won't work because (a) a slash (/) was added at the start, but especially (b) the browser does not accept a URI that's different from the page URI (i.e. not the same server == suspicious.) The only way I can think of to fix this one is to replace the URI with a URI on your server or put the code inline...
Okay! I got it to work. The recaptcha_ajax.js code needs to be in the recaptcha_init() function so it's always there. Then the $js code needs to be added immediately to the HTML of the button instead of using the drupal_add_js(). That way it works. However, this is not a lightbox2 bug, it comes down to a reCAPTCHA bug instead. So I guess I'll bounce that to the reCAPTCHA maintainers.
The change proposed in the following PHP snippet should not be used. It re-includes all the JavaScripts and that may cause other problems.
Comment #2
AlexisWilke CreditAttribution: AlexisWilke commentedAs I mentioned in my previous message, this is actually a reCAPTCHA bug and not a lightbox2 problem. At least, not directly.
I have two proposed solutions although either way we want to include the Google AJAX in the init function because that's just necessary there (you cannot get that code later because the browser refuses to load JavaScripts from a different server than the one used to load the page--for security reasons.)
First I propose to have a specialized test (Patch 1), but that is kinda ugly (a hack.) On the other hand, you don't really need to use the drupal_add_js() at all. You can simply append your JS to the HTML of the box (Patch 2). I propose the patches inline because it's easier to see the code changes and see which one you think is best for your module.
P.S. There is another drupal_add_js() call around like 135 which patch1 & 2 do not take in account. It should certainly be handled in a similar way. I propose patch 3, but that means the variable is defined twice. I should be safe though.
Patch 1:
Patch 2:
Patch 3:
Comment #3
hass CreditAttribution: hass commentedPlease share a patch. Is this also an issue in 7.x?
Comment #4
hass CreditAttribution: hass commentedComment #5
hass CreditAttribution: hass commentedClosing because of inactivity.