JavaScript Callbacks

The MTCaptcha widget supports the following callbacks

Callback Description
jsloaded-callback The MTCaptcha JavaScript library has loaded
rendered-callback The 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-callback The user has been verified. A verifiedToken will always be available on callback.
verifyexpired-callback The last verifiedToken has expired.
error-callback Some kind of error has occured, 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:

<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 Field Description
element The MTCaptcha DIV anchor DOM element.
domID The dom ID of the MTCaptcha DIV anchor DOM element.
verifiedToken The verifiedToken string. null if not verified.
isVerified Boolean indicating if the captcha is currently verified. If true, field verifiedToken will contain the token string.
isVisible Boolean indicating if the captcha is currently visible. See Developers Guide - Invisible Captcha to learn more about invisible captcha settings.
statusCode The current status of the captcha.
statusDesc The current status of the captcha in description.