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.
Captcha / Recaptcha are used to prevent spam and automated account creation.
Please provide the posibility to use captcha / recaptcha inside modal forms.
Currently no captcha image is displayed inside the modal form although it is displayed when using standard log in/register functionality.
Related modules:
http://drupal.org/project/captcha
http://drupal.org/project/recaptcha
Comment | File | Size | Author |
---|---|---|---|
#49 | 1463768-49.patch | 2.45 KB | shubham.prakash |
#39 | interdiff_32_38.txt | 711 bytes | Mike Lewis |
#38 | recaptcha-fix_modal_and_ajax-1463768-38.patch | 2.9 KB | Mike Lewis |
#32 | recaptcha-fix_modal-1463768-32-D7.patch | 2.35 KB | abramm |
| |||
#21 | 1463768-recaptcha-in-modal-forms.patch.txt | 2.33 KB | alemadlei |
Comments
Comment #1
arekanderu CreditAttribution: arekanderu commented+1
Comment #2
Alice Heaton CreditAttribution: Alice Heaton commentedcaptcha-image works with contact form and Modal Forms version 7.x-1.2
Comment #3
warmth CreditAttribution: warmth commentedCAPTCHA and Image CAPTCHA work, confirmed! But the size of the windows is not correct, it always gets scroller for me.
In the other hand Image CAPTCHA Refresh and reCAPTCHA but I think are because of an AJAX issue that must be reported to each module developer. The first one display the image but if you try to refresh the image the modal window try to reload but it won't make it. The second simply displays nothing.
Comment #4
ddrozdik CreditAttribution: ddrozdik commentedHi,
If you want to hide scroll you need configure module "modal form" and set width and height coefficients(please see my screenshot attached).
Also about Image CAPTCHA Refresh see my comment here.
Dmitry.
Comment #5
warmth CreditAttribution: warmth commentedThanks DmtryDrozdik! To solved it I have to modify: Modal popup medium -> Fixed (550x550)
Comment #6
Liam MorlandMarking #1872442: Modal forms + reCAPTCHA issue as duplicate of this.
Comment #7
pinkonomy CreditAttribution: pinkonomy commentedCaptcha image is not appearin on my modal webform...
How can i solve this?Should I do anything special?
thanks
Comment #8
christoph CreditAttribution: christoph commentedThe issue appears to be that the Google javascript code defined in Recaptcha - drupal_add_js('https://www.google.com/recaptcha/api/js/recaptcha_ajax.js', array('type' => 'external'));
is not loaded before the modal form opens. If you put this into a preprocess page hook (so that it loads the script in the main page and not the popup), I found it works fine.
Recaptcha (using Ajax API at least) only loads the javascript when the captcha is called, which for the modal popup is too late for the javascript to be available. You should see a javascript error saying that 'Uncaught ReferenceError: Recaptcha is not defined', which is a giveaway that this is happening.
For the moment I only see a workaround by forcing reCaptcha to load on the page load - not probably something worth doing in the module. CTools does, I think, allow calling of javascript from within the popup (ctools_ajax_command_attr), but I don't really understand that yet I'm afraid. That may be a possible route.
Comment #9
qwertmax CreditAttribution: qwertmax commentedI think there is not actually CTools problem.
This problem is in the fact of the CTools download necessary code like objects for Drupal.settings (Drupal.settings.recaptcha, Object {theme: "white", lang: "en", public_key: "some key", container: "recaptcha_ajax_api_container"})
but bug is in that the Drupal.behaviors.recaptcha.attach() called BEFORE (before CTools made a merge of Drupal.settings) and Recaptcha object isn't exist at that time.
so I did a hack on my side and do next thing:
WAS
after my changes:
I know that this is bad (really bad spike) but I'm working on fix for this issues.
Comment #10
qwertmax CreditAttribution: qwertmax commentedThe problem it in the race effect.
drupal_add_js('https://www.google.com/recaptcha/api/js/recaptcha_ajax.js', array('type' => 'external'));
this like in code load Recaptcha object, but while loading is in progress, form loaded and behaviors executed. That's why js execution break with error "Uncaught ReferenceError: Recaptcha is not defined"
one solution is in previous comment - to add
setTimeout
But it's bad solution because of timings.
I suggest to use library to solve that "race effect", here is my solution.
P.S. I created libraries/recaptcha folder with
libraries/recaptcha/recaptcha_ajax.js file - I got it from https://www.google.com/recaptcha/api/js/recaptcha_ajax.js page.
Comment #11
qwertmax CreditAttribution: qwertmax commentedComment #12
Liam MorlandThis looks very risky to me. How does a webmaster know when to update their local copy of recaptcha_ajax.js? I don't see how this is a robust fix anyway: Downloading recaptcha_ajax.js from the local web site is not sure to be faster than downloading it from Google.
Comment #13
qwertmax CreditAttribution: qwertmax commentedI can rewrite module and add option to use recaptcha_ajax from server or via CDN.
Comment #14
Liam MorlandI would like to avoid any solution which involves making a copy of the Google-hosted JS files. We never know when they would change.
Comment #15
Liam MorlandComment #16
eyeless CreditAttribution: eyeless commentedAdded make-compliant patch file for the race conditions.
Comment #17
galactus86 CreditAttribution: galactus86 commentedI am using the DEV version as it now works with Google reCaptcha. Google reCaptcha works great on webform, but does not show up in cTools modal. the above patch seems to be for the previous version. Anyone find a solution?
Comment #18
hass CreditAttribution: hass commentedComment #19
dczaretsky CreditAttribution: dczaretsky commentedConfirming this problem still exists in 7.x-2.0. The image and math captchas work in modal windows but not recaptcha. I've tried to add the google js file in hook_init but no affect.
Any word on a working solution?
Comment #20
alemadleiWhile going through the module's code, I came across this code:
Because it's an ajax request, the recaptcha javascript is never included in the ajax response settings (due to the usage of drupal_add_html_head.
I managed to get it working by commenting all the code that adds the tag and instead uncummenting the drupal_add_js. But the problem is that it only worked once. If I closed the modal and opened it again, then the captcha wouldn't load, which makes sense as by default it only executes once on load.
Doing some manual js calls, I was able to render it again by doing
From the javascript console.
I have an idea for a patch, which I'm not sure it's gonna work.
* Add a global flag, maybe trough functions with static get / set everytime a form with captcha is used.
* Add a behavior that executes on window.load() (hopefully after recaptcha has loaded the first time) and checks if the captcha element is empty. If so, renders it using the data it has.
* Add a hook_ajax_render_alter that checks if the flag was set. If so, then adds a setting variable or something that can help me identify that I can eventually call the added js behavior.
I will begin on this tomorrow morning,
If someone manages to read this by then, I would appreciate all the feedback regarding this approach or things I should consider.
Comment #21
alemadleiSo, after #20 and some playing around, the solution was simpler than originally planned.
Attached patch should make it work with modal forms.
General changes
Patch is to work against 7.x-2.0.
Should work against latest dev, but I didn't test.
Comment #22
hass CreditAttribution: hass commentedLooks like a dupe.
Comment #23
bredlen CreditAttribution: bredlen commented#21 confirmed working for me using Ajax Login-Register
Comment #24
rovoalso confirmed, #21 applied against the latest dev fixed it for me.
Comment #25
sidheswar CreditAttribution: sidheswar commented#21 gives me recaptcha in modal form. But when I check "I'm not a robot" it goes on loading and does not display the other popup of recaptcha.
Comment #26
chinhlc CreditAttribution: chinhlc commentednot for 7.x-2.1 ?
I can't apply for ctool ajax
Comment #27
dieppon CreditAttribution: dieppon as a volunteer commented#21 confirmed working for me on the dev version
Comment #28
jordilopezamat CreditAttribution: jordilopezamat as a volunteer commented#21 apparently working for me too on the dev version.. but after reCaptcha validation completion i'm getting an ajax error which is preventing the contact form to be submitted.
Any hints ?
Ok, i finally solved the AJAX issue applying this other Patch , as long as the one proposed here at #21
Comment #29
Mihai Chiriac CreditAttribution: Mihai Chiriac commentedI had the same issue as #28 this morning.
Fixed it by changing this
drupal_get_path('module', 'recaptcha') . '/js/recaptcha.js' => array(),
to this
drupal_get_path('module', 'recaptcha') . '/recaptcha.js' => array(),
Just remove js from the path.
Comment #30
swetaranjan CreditAttribution: swetaranjan as a volunteer commentedCould any one share proper working code or patch of recaptcha version - 7.x-2.0 .
Comment #31
PapaGrande#21 works but so does https://www.drupal.org/node/2493183#comment-12178132. Since that issue is still open and getting some D8-love, I would suggest folks go there as it's more up to date.
Comment #32
abramm#21 works, however, due to an incorrect external script declaration the JS gets aggregated by Drupal's built-in 'Aggregate JavaScript files' function.
As a result, captcha stops working in a month or so (since recaptcha's JS expires for security reasons).
Attaching fixed patch + cleanup of old code.
The patch may be useful for people using #21.
Comment #34
gurunathan CreditAttribution: gurunathan commentedhttps://www.drupal.org/project/recaptcha/issues/2493183#comment-12178132
fixed the issue
Comment #35
visway12 CreditAttribution: visway12 commented#32 works perfect for modal dialogue box, but not working on Colorbox. Please refer this patch https://www.drupal.org/files/recaptcha_ajax_1119086.patch for colorbox and check this can be merged and make it work at both places.
Comment #36
khiminrm CreditAttribution: khiminrm at Lemberg Solutions commentedPatch from #32 successfully was applied to recaptcha 7.x-2.2 and helped to fix recapatcha in modal using dialog module. Thanks!
Comment #37
manish34jain CreditAttribution: manish34jain as a volunteer and commentedPatch from #32 is working. Thanks!
Comment #38
Mike Lewis CreditAttribution: Mike Lewis commented#32 worked for me except that it broke multi-lingual support. I re-rolled it with the language support preserved.
Comment #39
Mike Lewis CreditAttribution: Mike Lewis commentedHere's an interdiff between 32 and 38 for reference.
Comment #40
Mike Lewis CreditAttribution: Mike Lewis commentedComment #43
gurunathan CreditAttribution: gurunathan commented#32 didn't work for me.
Comment #44
firewaller CreditAttribution: firewaller commented#38 works for me when using modal_forms
Comment #45
robertoperuzzoI fixed using https://www.drupal.org/project/recaptcha/issues/2493183#comment-10199569.
Drupal 7.60
captcha 1.5
recaptcha 2.2
Comment #46
firewaller CreditAttribution: firewaller commented#38 and the linked comment from #45 look very similar FYI
Comment #47
gregglesThis seems really similar to #2875698: Drupal 7.x: Ajax support / Use behaviors for 2.x doesn't it? Does that patch address this issue for anyone?
Comment #48
firewaller CreditAttribution: firewaller commentedFYI #38 needs a re-roll.
Comment #49
shubham.prakash CreditAttribution: shubham.prakash at OpenSense Labs commentedComment #50
MeenakshiG CreditAttribution: MeenakshiG at OpenSense Labs for DrupalFit commentedComment #51
FiNeX CreditAttribution: FiNeX as a volunteer commentedHi, patch 49 works fine. Thanks :-)
Comment #52
imoreno CreditAttribution: imoreno commentedHi, it's december 2022, patch on 49 works fine. Thanks :-)