SMS code checker

vbarlakoski 29 Feb, 2012
Hello again!

I want to add field where user can enter code sent by SMS. But it troubles me where do i put the checker code, so if it's wrong, to return error message?

the code is
<?PHP

function mobio_checkcode($servID, $code, $debug=0) {

	$ret = 0;

	$mobio_socket = fsockopen("www.mobio.bg", 80);

	if(!$mobio_socket) {
		if($debug)
			echo "Unable to connect to mobio.bg server\n";
		$ret = 0;
	}else{
		$request .= "GET http://www.mobio.bg/code/checkcode.php?servID=$servID&code=$code HTTP/1.0\r\n\r\n";
		fwrite($mobio_socket, $request);
		$result = fread($mobio_socket, 255);
		if(strstr($result, "PAYBG=OK")) {
			$ret = 1;
		}else{
			$ret = 0;
			if($debug)
				echo strstr($result, "PAYBG");
		}
		fclose($mobio_socket);
	}

	return $ret;
}


$servID = 16;
$code = $_REQUEST["code"];
if(mobio_checkcode($servID, $code, 1) == 1) {
	echo "Valid code";
}else{
	echo "Invalid code";
}


?>


Thanks!
GreyHead 29 Feb, 2012
Hi vbarlakoski,

Ths look like a case to use Ajax to check the code when the user types it in. Alterantively you can use it in he Server side validation after the form is submitted.

Bob
vbarlakoski 29 Feb, 2012
Yup, i was thinking about checking after submit, like captcha code does. But,
can you help me where to put the validation code, and how should i connect with the field?
GreyHead 29 Feb, 2012
Hi vbarlakoski,

Which version of ChronoForms are you using? You can find the version from Site Admin | Extensions | Install/Uninstall | Components in Joomla! 1.5 or Site Admin | Extensions | Extension Manager | Manage in Joomla! 1.6/1.7/2.5.

Bob
vbarlakoski 29 Feb, 2012
Hello!

Its 4.0 RC3.11 Joomla 2.5.
GreyHead 29 Feb, 2012
Hi vbarlakoski ,

Thank - then you can use the Custom Serverside Validation action in the On Submit event to run the check.

There's a new release CFv4 RC4 that you should upgrafd to as it has some bug-fixes as well as new features.

Bob
vbarlakoski 29 Feb, 2012
Thanks Bob!

I`ll check it. Just one more question, because the SMS code field is not required (if you fill it, you`ll get extra options, if you not, you have basic options) how can i set, if the field is filled up, then check after submit. Or there is no other way?
GreyHead 29 Feb, 2012
Hi vbarlakoski,

I'm sorry I don't understand your question :-(

Bob
vbarlakoski 01 Mar, 2012
I`ll try to be more clear🙂

SMS code field is not REQUIRED, so i want to check it only if its filled up.

How can i finish it?

Thanks!
GreyHead 01 Mar, 2012
Hi vbarlakoski,

In the Serverside validation check if there is an entry in the form data. Assuming that the input is named sms_code:
<?php
if ( !isset($form->data['sms_code']) && $form->data['sms_code'] ) {
  // run the check code
}
?>


Bob
vbarlakoski 01 Mar, 2012
Super duper!

I will let you know if it works!
vbarlakoski 15 Mar, 2012
Hello Bob!


<?php 
if ( (isset($form->data['input_text_21'])) && ($form->data['input_text_21'] != '')) {
// run the check code
}
?>


This is the actual code for field checking thats work!

So, thanks🙂 It Works!
This topic is locked and no more replies can be posted.