Skip to main content

JavaScript Callbacks

The MTCaptcha widget supports the following callbacks

CallbackDescription
jsloaded-callbackThe MTCaptcha JavaScript library has loaded.
rendered-callbackThe MTCaptcha widget is rendered (made visible). This may not be called if captcha is kept invisible via the use of Low Friction or IP Whitelist invisible captcha in site settings.
verified-callbackThe user has been verified. A verifiedToken will always be available on callback.
verifyexpired-callbackThe last verifiedToken has expired.
error-callbackSome kind of error has occurred, such as bad sitekey, or internet connection lost.

To enable callbacks, us the following pattern and config params .

<script>
function mt_jsloadedcb()
{
console.log("mt_jsloadedcb()");
}

function mt_renderedcb(state)
{
console.log("mt_renderedcb(state)");
console.log("state => "+JSON.stringify(state));
}
function mt_verifiedcb(state)
{
console.log("mt_verifiedcb(state)");
console.log("state => "+JSON.stringify(state));
}
function mt_verifyexpiredcb(state)
{
console.log("mt_verifyexpiredcb(state)");
console.log("state => "+JSON.stringify(state));
}
function mt_errorcb(state)
{
console.log("mt_errorcb(state)");
console.log("state => "+JSON.stringify(state));
}
</script>

<script>
var mtcaptchaConfig = {
"sitekey": "<YOUR SITEKEY>",

"jsloaded-callback": "mt_jsloadedcb",
"rendered-callback": "mt_renderedcb",
"verified-callback": "mt_verifiedcb",
"verifyexpired-callback": "mt_verifyexpiredcb",
"error-callback": "mt_errorcb"
};
...
</script>
‍```
The callback config params also support javascript function as value. eg:

```html
<script>
var mtcb = {};
mtcb.jsloaded = function(){
console.log("mtcb.jsloaded()");
}
</script>

<script>
var mtcaptchaConfig = {
"sitekey": "<YOUR SITEKEY>",
"jsloaded-callback": mtcb.jsloaded
};
...
</script>

The Callback State Argument & Fields

All callbacks that contains a ‘state’ argument has the following properties. eg

<script>
function mt_renderedcb(state)
{
console.log("state => "+JSON.stringify(state));
}
</script>

/*
output in console:

state =>
{
"element": <element>,
"domID":"mtcaptcha",
"verifiedToken":null,
"isVerified":false,
"isVisible": true,
"statusCode":2200,
"statusDesc":"Captcha rendered"
}
*/

The callback state argument fields explained

State FieldDescription
elementThe MTCaptcha DIV anchor DOM element.
domIDThe DOM ID of the MTCaptcha DIV anchor DOM element.
verifiedTokenThe verifiedToken string. null if not verified.
isVerifiedBoolean indicating if the captcha is currently verified. If true, the verifiedToken field will contain the token string.
isVisibleBoolean indicating if the captcha is currently visible. See Developers Guide - Invisible Captcha to learn more about invisible captcha settings.
statusCodeThe current status of the captcha.
statusDescThe current status of the captcha in description.