fabianwennink / IconCaptcha-PHP

A self-hosted, customizable, easy-to-implement and user-friendly captcha for PHP.
https://www.fabianwennink.nl/projects/IconCaptcha/
MIT License
134 stars 25 forks source link

I have issue to reload iconCaptcha #11

Closed varkao closed 1 year ago

varkao commented 2 years ago

Hello, there is a way to reload or reset the captcha once the verification is completed (without refresh the page) I'm using an ajax form, and my problem is that when the client receives a false message, I merely need to refresh the captcha to allow the client to make another request.

fabianwennink commented 2 years ago

Hi @GAMY-lib, sorry for the (really) late reply. Currently, there is no public function available to reset the captchas on a page with. For now, you can use the following code snippet to reset your captchas. It extends the IconCaptcha script with a new function, which will later be properly implemented into the source code.

The snippet can be placed anywhere (after the script file was loaded), but right before initializing a captcha seems like the best place to put it. To use it, simply call IconCaptcha.reset() and it will clear your captchas. Note that this will clear/reset every captcha on the page. It's kind of duplicated code (cause of the copied options), but there is no other way right now. Hope this helps!

IconCaptcha.reset = function() {

   this.nodes = null;

   this.init('.iconcaptcha-holder', { 
        general: {    // your form options, same as when you initiated the captcha.
            validationPath: '../src/captcha-request.php',
            fontFamily: 'Poppins',
            credits: 'show',
        },
       ... // remaining options
   })
}
fabianwennink commented 1 year ago

Hi @GAMY-lib! Just letting you know that the reset function is now available in release version 3.1.0. The Wiki will be updated shortly to include more information about the function.