I'm handling my forms with ajax (remote: true) and I'm struggling to figure out how I can reset the recaptcha after a successful post. Any help would be appreciated :)
I know this is a little late but I just had to solve this problem so hopefully my response can help someone else. Basically, since my form is a create action, I edited my create.js file to update the token on failed submission. Here's how:
Here's a portion of my form where I render a partial that include my captcha tag:
Japanese translator turned software engineer. I work mostly with Ruby and Rails, but love working on both the backend and the frontend. Currently a computer science student @ University of Colorado.
Location
Connecticut
Education
University of Colorado, Ohio State University, IUC (for Japanese)
Japanese translator turned software engineer. I work mostly with Ruby and Rails, but love working on both the backend and the frontend. Currently a computer science student @ University of Colorado.
Location
Connecticut
Education
University of Colorado, Ohio State University, IUC (for Japanese)
Unfortunately, I've never done the resetting with ajax myself, so I can't give you any tips from my own experience. I was just checking out some other blogs and the google documentation, though, and you might be able to use the reCaptcha javascript api and reset it with grecaptcha.reset(widgetId);. This blog post mentions it but not sure if it works.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Felice, great article!
I'm handling my forms with ajax (remote: true) and I'm struggling to figure out how I can reset the recaptcha after a successful post. Any help would be appreciated :)
Thanks,
Ben
I know this is a little late but I just had to solve this problem so hopefully my response can help someone else. Basically, since my form is a
create
action, I edited mycreate.js
file to update the token on failed submission. Here's how:Here's a portion of my form where I render a partial that include my captcha tag:
Here's the complete partial:
potential_clients/captcha_field
:Finally, in my
create.js
I do the following:This will re-render the portion of the form with the token and since it hits the helper function, a new token is generated!
Nice! Thank you so much for sharing your solution!
Hi Ben, thanks for reading!
Unfortunately, I've never done the resetting with ajax myself, so I can't give you any tips from my own experience. I was just checking out some other blogs and the google documentation, though, and you might be able to use the reCaptcha javascript api and reset it with
grecaptcha.reset(widgetId);
. This blog post mentions it but not sure if it works.