-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rails 7 / Turbo : g-recaptcha-response is empty #407
Comments
can you add this tip to the readme or make a PR to fix the issue ?
…On Sun, Apr 17, 2022 at 11:07 PM Jey Geethan ***@***.***> wrote:
Whenever I am using rails 7 which is essentially saying using turbolinks
for forms, my g-recaptcha-response is blank spaces " "
Version: recaptcha_v2
*Solution*
If I turn off the turbolinks, data: { turbo: false } in the form, it works
again.
—
Reply to this email directly, view it on GitHub
<#407>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACYZ2YKRPY5JUAATUAJ43VFT32HANCNFSM5TVBRAAA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Having the same issue with Rails 7. |
@byteg @jeygeethan if you inspect html code you can see that there are two 'g-recaptcha-response' inputs so please use |
@rzepetor thank you so much! Now it works :) |
@byteg I have other problem, recaptcha verify always fail and I don't know why, its render normally in form, green check icon is showing, in params I have 'g-recaptcha-response' but it always fails 😞 maybe you know why or have any clue? |
For anyone who's having this issue with Turbo and does not want to disable it, this article should help: https://dev.to/fadrien/rails-devise-and-recaptcha-with-hotwire-turbo-and-stimulus-2hoh Actually, I had exactly the same issue: even if Turbo is disabled, captcha was reported as invalid on every request. Also, if you are using only recaptcha v2, make sure to include the corresponding script somewhere on your page: <% provide :scripts do %>
<script src="https://www.recaptcha.net/recaptcha/api.js" async="" defer=""></script>
<% end %> |
some readme instructions for this would be nice, can you make a PR ?
…On Tue, Jun 21, 2022 at 6:29 AM Ilya Krukowski ***@***.***> wrote:
For anyone who's having this issue, this article should help:
https://dev.to/fadrien/rails-devise-and-recaptcha-with-hotwire-turbo-and-stimulus-2hoh
Also, if you are using only recaptcha v2, make sure to include the
corresponding script somewhere on your page:
<% provide :scripts do %> <script src="https://www.recaptcha.net/recaptcha/api.js" async="" defer=""></script>
<% end %>
—
Reply to this email directly, view it on GitHub
<#407 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACYZ42IRMDVERCI6CIF7LVQG7UVANCNFSM5TVBRAAA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I'd love to. However I did some more experiments and it seems this setup is only partially working. For example:
For now I haven't found a way to fix this :( |
Actually, I might have found a potential solution. Will experiment more and if it works, I'll submit a PR |
Setting I wonder why add a textarea in noscript? recaptcha/lib/recaptcha/helpers.rb Lines 76 to 80 in 1ac1d61
|
Can you try digging into the git history and making a fixup PR if that
seems to be just an accident ?
…On Sun, Aug 7, 2022 at 1:37 AM Rei ***@***.***> wrote:
Setting noscript: false solved my problem.
I wonder why add a textarea in noscript?
https://github.com/ambethia/recaptcha/blob/1ac1d61ab1e00c85bf282cb662194827a4bfd957/lib/recaptcha/helpers.rb#L76-L80
—
Reply to this email directly, view it on GitHub
<#407 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACYZ4QE3JLK6E4DJQF4LLVX5YUJANCNFSM5TVBRAAA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
is there an improvement you can suggest or maybe some better docs ? |
Currently I use this way: Add api script in layout's head: <head>
...
<script src="https://www.recaptcha.net/recaptcha/api.js" async defer></script>
</head> Do not add this script in body, it will cause the api script to be loaded repeatedly.
Add this element where recaptcha is required: <div class="g-recaptcha" data-controller="recaptcha" data-sitekey="<%= ENV['RECAPTCHA_SITE_KEY'] %>"></div> When this page is the first page visited, it will be rendered by the api script. A stimulus controller is required to handle the case of turbolinks visit. // recaptcha_controller.js
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() {
// Skip this if grecaptcha has not been loaded or has already been rendered.
if (window.grecaptcha && window.grecaptcha.render && this.element.childElementCount == 0) {
grecaptcha.render(this.element, {
'sitekey' : this.element.dataset.sitekey
})
}
}
} The above method can solve the problem of repeated loading and rendering timing in the turbolinks environment. The noscript content is used to add a fallback validation method. But I found that this method seems to be invalid. You can turn off javascript and visit this page to test, it will prompt you to enable javascript: https://www.google.com/recaptcha/api2/demo But there is another page that shows it works, I don't know why: https://www.google.com/recaptcha/api/fallback?k=6LdAvUIUAAAAAHjrjmjtNTcXyKm0WKwefLp-dQv9 |
There's no need to make it so complex. The method I've described here https://github.com/ambethia/recaptcha/wiki/Recaptcha-with-Turbo-and-Stimulus works fine with Turbo (not Turbolinks) and Stimulus. I've been using it for a couple of months already and everything seems to be okay |
Thanks! |
Whenever I am using rails 7 which is essentially saying using turbolinks for forms, my g-recaptcha-response is blank spaces " "
Version: recaptcha_v2
Solution
If I turn off the turbolinks, data: { turbo: false } in the form, it works again.
The text was updated successfully, but these errors were encountered: