Skip to content
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

improvements for invisible_recaptcha_tags? #220

Closed
philipqnguyen opened this issue Apr 20, 2017 · 7 comments
Closed

improvements for invisible_recaptcha_tags? #220

philipqnguyen opened this issue Apr 20, 2017 · 7 comments

Comments

@philipqnguyen
Copy link
Contributor

Thanks @juampi for originally implementing invisible_recaptcha_tags! I was able to successfully get it to work on my app.

Now, I'm wondering if invisible_recaptcha_tags public api has diverged too much from the original intention?

The two things you must do differently from recaptcha_tags are:

  1. You must specify a callback function, which would be called after verification with Google's reCAPTCHA service. Ideally, this callback function would submit the actual form.

  2. The invisible_recaptcha_tags will generate a submit button for you. You should not need to add a f.submit or submit_tag to your form.

Do you think we should automate the callback of the form submission and to remove the generation of the submit button?

@grosser
Copy link
Collaborator

grosser commented Apr 22, 2017

I think it's easy enough ... automating JS is rarely fun ...
We could add a submit: '#foobar' option to it that then generates the JS inline, but it shouldalways be an option for cases where js injection is disabled.

@philipqnguyen
Copy link
Contributor Author

What do you think about adding a default for when there is no option passed?

Here is something that has come to my mind:

// app/assets/javascripts/application.js
//= require recaptcha
<%= form_for @foo do |f| %>
  <!-- other form fields -->
  <%= invisible_recaptcha_tags %> <!-- no options passed, no button generation. -->
  <%= f.submit 'Save' %>
<% end %>

The recaptcha.js would be a new file included in the gem. It would contain some js functions to stop the form on submit, wait for Google's reCAPTCHA verification response, and then it resumes the submission.

Just an idea.

@grosser
Copy link
Collaborator

grosser commented Apr 23, 2017

sounds good ... maybe make it require recaptcha/invisible so it's clear what it is for

@philipqnguyen
Copy link
Contributor Author

I can try to work on this on my free time. Though if someone else wants to take a stab, be my guest.

@chrismd3
Copy link

I'd really like to see this. I was looking for a way to do something like this with the existing tag already.

philipqnguyen added a commit to philipqnguyen/recaptcha that referenced this issue Sep 16, 2017
This is a work in progress commit and looking for some ideas.
It is working towards the first part of ambethia#220.

This adds a default callback that calls the function
`invisibleRecaptchaSubmit` if no callback was passed to
`invisible_recaptcha_tags`

The drawback to this approach is that it won't work if there are
multiple recaptcha forms.
philipqnguyen added a commit to philipqnguyen/recaptcha that referenced this issue Sep 24, 2017
This adds a default callback that calls the function
`invisibleRecaptchaSubmit` if no callback was passed to
`invisible_recaptcha_tags`. The function, `invisibleRecaptchaSubmit`,
uses the `closest()` method to find the closest form to the
`.g-recaptcha` element. However, not all browsers support `closest()`,
so in that case, a polyfill of `closest` is executed. The polyfill is
based on MDN's polyfill suggestion which should support IE9+
https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill

The drawback to this approach is that it won't work if there are
multiple recaptcha forms. If you want to use invisible_recaptcha_tags
with multiple forms, you would still need to use custom callbacks.
philipqnguyen added a commit to philipqnguyen/recaptcha that referenced this issue Oct 7, 2017
This adds a default callback that calls the function
`invisibleRecaptchaSubmit` if no callback was passed to
`invisible_recaptcha_tags`. The function, `invisibleRecaptchaSubmit`,
uses the `closest()` method to find the closest form to the
`.g-recaptcha` element. However, not all browsers support `closest()`,
so in that case, a polyfill of `closest` is executed. The polyfill is
based on MDN's polyfill suggestion which should support IE9+
https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill

The drawback to this approach is that it won't work if there are
multiple recaptcha forms. If you want to use invisible_recaptcha_tags
with multiple forms, you would still need to use custom callbacks.
philipqnguyen added a commit to philipqnguyen/recaptcha that referenced this issue Oct 15, 2017
This adds a default callback that calls the function
`invisibleRecaptchaSubmit` if no callback was passed to
`invisible_recaptcha_tags`. It will traverse the DOM upwards to find
the closest form to submit.

The drawback to this approach is that it won't work if there are
multiple recaptcha forms. If you want to use invisible_recaptcha_tags
with multiple forms, you would still need to use custom callbacks.
grosser added a commit that referenced this issue Oct 15, 2017
Add default callback for invisible recaptcha #220
@PascalPixel
Copy link

This helped me a lot as a first time user, seeing that empty thing there, thanks!

@philipqnguyen
Copy link
Contributor Author

I'll close this issue now since #238 pretty much solved the pain that this issue was surfacing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants