Page 1 of 1

How to check Captcha?

Posted: Sat Mar 29, 2014 5:03 pm
by seregarem
I need to check Captcha before to send the result of a form (FormBuilder). So,

Code: Select all

function setCaptcha(){
if (request.readyState == 4){
	if (request.status == 200){
        responseXml = request.responseXML;
        xmlDoc = responseXml.documentElement;
        action = xmlDoc.getElementsByTagName("action")[0].firstChild.data;
		alert(action);
        if (action == 'ok'){
			b=true;
		}else{
			b=false;
			alert('Error!');
		}
    }
  }
}

url = "../php/get_captcha.php?cap="+m5ce14fbrp_captcha_phrase.value;
//		alert(url);
		createRequest();
		request.open("GET", url, false);
		request.onreadystatechange = function() {setCaptcha();};
		request.send(null);
PHP

Code: Select all

require '../include.php'; // (from site's root )
$cap=$_GET['cap'];
$captcha = &$gCms->getModuleInstance('Captcha');
if(is_object($captcha)){
$validated=$captcha->CheckCaptcha($cap);
if($validated==true)
	$response = '<?xml version="1.0" encoding="utf8" standalone="yes"?><response><action>ok</action></response>';
else $response = '<?xml version="1.0" encoding="utf8" standalone="yes"?><response><action>bad</action></response>';

} else $response = '<?xml version="1.0" encoding="utf8" standalone="yes"?><response><action>no object</action></response>';

header('Content-Type: text/xml');
echo $response;
But always $validated returns false. What's wrong???

Re: How to check Captcha?

Posted: Sat Mar 29, 2014 5:13 pm
by Jo Morg
If you are using Form Builder and Captcha modules as designed FB already has built in Captcha integration afaik. Check demo templates for sample on how it is used. No need for all that...

Re: How to check Captcha?

Posted: Sat Mar 29, 2014 5:39 pm
by seregarem
I have no need to reload the page... I need to show an alert, after a submit button click...

Re: How to check Captcha?

Posted: Sat Mar 29, 2014 6:10 pm
by calguy1000
a: We do not support accessing CMSMS API's externally like this.
b: This board is for people writing modules and contributing to CMSMS not for site developers.
c: This topic is related to third party modules. Not to the core.

Topic closed.