This BotDetect Captcha PHP code example shows how to use custom BotDetect client-side events to execute user-defined JavaScript code at various stages of the Captcha challenge workflow.
Client-side Captcha object initialization, Captcha image reloading, Captcha sound playback, built-in Captcha Ajax validation, and Captcha help link clicks all have a number of related client-side "events" and hooks where user-defined client-side callbacks can be injected.
User code can be associated with Captcha workflow events using the BotDetect.RegisterCustomHandler()
function, as shown in the example JavaScript code.
Loading the form will initialize the client-side Captcha
object (created by the BotDetect.Init()
JavaScript call included in Captcha markup), and result in the PostInit
event.
Clicking the Captcha sound icon will result in the PrePlaySound
event before the audio elements are added to the page DOM. There is no PostPlaySound
event since not all browsers allow user callbacks when browser sound playing finishes.
Clicking the Captcha reload icon will result in PreReloadImage
and PostReloadImage
events, executed before and after the Http request loading the new Captcha image from the server.
Clicking the Captcha image (i.e. the included Captcha help link) will result in the OnHelpLinkClick
event.
Typing in a Captcha code and clicking the Validate button will first result in the PreAjaxValidate
event, and later in either AjaxValidationFailed
or AjaxValidationPassed
depending on whether the server responds that the typed-in Captcha code was correct or not. In case of Ajax asynchronous request errors, AjaxValidationError
will be called.
BotDetectâ˘
trademark in the background of 50% of all Captcha images generated.These limitations are removed if you upgrade your BotDetect license.
BotDetect PHP Captcha Library version 4.1.0 Free loaded by PHP version 7.2.34-38+ubuntu18.04.1+deb.sury.org+1