Sunday, May 19, 2024
18
rated 0 times [  21] [ 3]  / answers: 1 / hits: 80977  / 10 Years ago, fri, december 19, 2014, 12:00:00

I have a registration form with the new google recaptcha widget on it. When a user submits info, we check the validation with javascript and return the problems to the page (ex: please use a valid phone number). however, since the page doesn't reload, when the user enters correct info and goes to submit again (without having to do the recaptcha again)...the recaptcha is no longer valid and they can't submit without reloading the page.



is there a good solution to this? can I reload the widget somehow? i tried grecaptcha.render but it didn't really do anything.



EDIT:



When I try to render the widget again, it says placeholder element must be empty



I tried emptying the element which seemed to work ($('.g-recaptcha').empty();) and then rendering but it still threw the same error.


More From » ruby-on-rails

 Answers
30

The method you are looking for is grecaptcha.reset()



However, in order for this function to work you have to render the reCaptacha explicitly like this : <script src=https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit async defer></script>


[#68431] Wednesday, December 17, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckaylab

Total Points: 311
Total Questions: 120
Total Answers: 93

Location: Montenegro
Member since Thu, Jun 16, 2022
2 Years ago
;