-
Notifications
You must be signed in to change notification settings - Fork 56
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
How to reset multiple captchas? #74
Comments
Well I can save widgetID to variable in this function, but it works only if "-" symbol replace to "_". private function renderCaptchas(array $captchas)
{
return implode(PHP_EOL, array_map(function($captcha) {
return "if (document.getElementById('$captcha')) { ".str_replace('-', '_', $captcha)." = grecaptcha.render('$captcha', {'sitekey' : '{$this->siteKey}'}); }";
}, $captchas));
} and then use that variable in js like this if (typeof grecaptcha !== 'undefined') {
var id = $('.g-recaptcha').attr('id');
grecaptcha.reset(eval(id.replace('-', '_')));
} It works, but maybe there is some out-of-box function? |
I'm working on it 👍 |
The following PR allows you to access the rendered captchas by using the Try to make the same changes as this class and tell me if it fixes your issue! Example: <!--Other scripts-->
<script>
function resetAllCaptchas() {
window.noCaptcha.renderedCaptchas.forEach(function (captcha) {
grecaptcha.reset(captcha.id);
});
}
</script> |
Thank you, it worked! But may I ask you, maybe you can add captchas in array like this?
Now we can apply to id of captcha using name as a key, no need to foreach whole array if we need to reset just one captcha.
It is necessary to check keys in array before reset or it can crash, though. |
You can use this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find But I think I can extend the window.noCaptcha functionalities. Stay tuned |
I've added a new JS API to manage the captchas with ease: // Get all the rendered captchas collection
window.noCaptcha.captchas
// Reset a captcha by name
window.noCaptcha.reset(name)
// Reset a captcha by id
window.noCaptcha.resetById(id)
// Get a captcha object by name
window.noCaptcha.get(name)
// Get a captcha object by id
window.noCaptcha.getById(id)
// Find a captcha object in the collection
window.noCaptcha.find(callback)
// Render a captcha
window.noCaptcha.render(name, sitekey) |
Hi!
How can I reset captcha by opt_widget_id (as they say on google captcha docs)?
When I try to reset captcha by attribute 'id' in div with 'g-recaptcha' class, it does not work.
On StackOverflow there is a answer with that solution:
but in
\Arcanedev\NoCaptcha\NoCaptcha::renderCaptchas
function you do render captchas without saving widget ID to anywhere
Maybe there is some function to get widgetID?
The text was updated successfully, but these errors were encountered: