If the entered code cannot be validated successfully, a redirect to the original form page is issued with an embedded error code. Most programmers choose to extract this error code and then display a custom error message based on its value. Below, we show a sample code to extract the error code value and trigger a custom JavaScript alert. You have the freedom of replacing these alerts with your own custom messages. The captchapro_util.js file is provided for your convenience and contains necessary functions for extraction of the error code value from the form URL.
To activate the basic error processing, add the following JavaScript code to the web page where you have online form with CAPTCHA:
<script language="javascript" type="text/javascript" src="/global/js/captchapro_util.js"></script>
var captchaErrorCode = parseInt(getParameterValue(document.location, "captchaError"));
var errorMsg = " Error [" + captchaErrorCode + "]: " ;
if (!isNaN(captchaErrorCode)) {
switch(captchaErrorCode) {
case 1:
errorMsg += "Incorrect CaptchaPro value. Please re-enter it again as shown in the picture.";
break;
case 2:
errorMsg += "Invalid CaptchaPro key";
break;
case 12:
errorMsg += "Cannot conect to form controller. Please check your CaptchaPro settings.";
break;
default:
errorMsg += "General. Please check your CaptchaPro settings.";
break;
}
alert(errorMsg);
}