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

Refresh captcha #3

Closed sovetski closed 5 years ago

sovetski commented 5 years ago

Hello how I can refresh the captcha on front page once I give an error in PHP ?

fabianwennink commented 5 years ago

The captcha should automatically refresh after a few seconds when it receives an error from the backend during initialization. Additionally, you can listenen to the 'error.iconCaptcha' event and perform actions when it's fired.

sovetski commented 5 years ago

The captcha refresh automatically when it receives an error from only if user selected the bad image.. How i can refresh captcha like google recaptcha ? ( for exemple in google recaptcha the code is : grecaptcha.reset(); https://stackoverflow.com/questions/3371314/how-to-reload-recaptcha-using-javascript )

fabianwennink commented 5 years ago

Sorry for the late response. Right now, it is not possible manually refresh the captcha. However, as there is a 'resetCaptcha' function present in the JS file (see https://github.com/fabianwennink/IconCaptcha-Plugin-Front-End/blob/master/src/js/icon-captcha.js#L259) - which does exactly what you want - you can modify the code and make the function accessible from outside of the plugin. Currently I don't have time to do it myself, but I'll add it in the near future.

sovetski commented 5 years ago

Hi, i have modified your file, if you want you can publish this file for other users who have the same problem.

For that, go to line 259 : https://github.com/fabianwennink/IconCaptcha-Plugin-Front-End/blob/master/src/js/icon-captcha.js#L259 and add this code after resetCaptcha(); function

` /**

$('.captcha-holder').iconCaptcha.refreshCaptcha();