Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Ajax captcha validation


chibib0

Recommended Posts

Hi,

 

I managed to put the review form and make it work on the product's page. However, I want to add a captcha on the form and the validation of it should be ajax based, meaning when the customer inputted incorrect captcha it will automatically notify the customer that it is incorrect in real time without redirections. I tried a lot of ajax captcha script but i can't seem to make it work in oscommerce.

 

Please help me..

Thank you.

Link to comment
Share on other sites

a several captcha on the form and the validation is available but all of them are basic and non ajax. check the Ads-on section of this website.

Please read this line: Do you want to find all the answers to your questions? click here. As for contribution database it's located here!

8 people out of 10 don't bother to read installation manuals. I can recommend: if you can't read the installation manual, don't bother to install any contribution yourself.

Before installing contribution or editing/updating/deleting any files, do the full backup, it will save to you & everyone here on the forum time to fix your issues.

Any issues with oscommerce, I am here to help you.

Link to comment
Share on other sites

I managed to have the captcha validation on my review form and the captcha validation works however, the alerts when you did not inputted the required fields doesn't appear on the pop-up alert and only the captcha validation pop-up alert is being displayed when you inputted wrong captcha and when I don't input the correct fields but the captcha is correct the form submits..

 

here is my javascript code:

<script type="text/javascript">
    var url = '<?php echo tep_catalog_href_link('captcheck.php?code=');?>';
    var captchaOK = 2;  // 2 - not yet checked, 1 - correct, 0 - failed

    function getHTTPObject()
    {
    try {
    req = new XMLHttpRequest();
	  } catch (err1)
	  {
	  try {
	  req = new ActiveXObject("Msxml12.XMLHTTP");
	  } catch (err2)
	  {
	  try {
	    req = new ActiveXObject("Microsoft.XMLHTTP");
	    } catch (err3)
	    {
req = false;
	    }
	  }
}
    return req;
}

    var http = getHTTPObject(); // We create the HTTP Object	   

    function handleHttpResponse() {
    if (http.readyState == 4) {
	    captchaOK = http.responseText;
	    if(captchaOK != 1) {
		  alert('The entered code was not correct. Please try again');
		  document.product_reviews_write.code.value='';
		  document.product_reviews_write.code.focus();
		  return false;
		  }
		  document.product_reviews_write.submit();
	   }
    }
   function checkcode(thecode) {
    http.open("GET", url + escape(thecode), true);
    http.onreadystatechange = handleHttpResponse;
    http.send(null);
    }
function checkForm() {
 var error = 0;
 var error_message = "<?php echo JS_ERROR; ?>";
 // Now the Ajax CAPTCHA validation
 checkcode(document.product_reviews_write.code.value);
 return false;
 var review = document.product_reviews_write.review.value;
 var firstname = document.product_reviews_write.customers_firstname.value;
 var lastname = document.product_reviews_write.customers_lastname.value;
 var thecode = document.product_reviews_write.code.value;
 if (firstname.length < <?php echo ENTRY_FIRST_NAME_MIN_LENGTH; ?>) {
   error_message = error_message + "<?php echo JS_FIRST_NAME; ?>";
   error = 1;
 }
 if (lastname.length < <?php echo ENTRY_LAST_NAME_MIN_LENGTH; ?>) {
   error_message = error_message + "<?php echo JS_LAST_NAME; ?>";
   error = 1;
 }
 if (review.length < <?php echo REVIEW_TEXT_MIN_LENGTH; ?>) {
   error_message = error_message + "<?php echo JS_REVIEW_TEXT; ?>";
   error = 1;
 }
 if ((document.product_reviews_write.rating[0].checked) || (document.product_reviews_write.rating[1].checked) || (document.product_reviews_write.rating[2].checked) || (document.product_reviews_write.rating[3].checked) || (document.product_reviews_write.rating[4].checked)) {
 } else {
   error_message = error_message + "<?php echo JS_REVIEW_RATING; ?>";
   error = 1;
 }
 if (thecode.length < 4) {
   error_message = error_message + "Please enter the code on the image.";
   error = 1;
 }
 if (error == 1) {
   alert(error_message);
   return false;
 } else {
   return true;
 }
}
</script>

 

Please help me coz i think im really close to this implementation.

Thank you.

Link to comment
Share on other sites

I managed to have the captcha validation on my review form and the captcha validation works however, the alerts when you did not inputted the required fields doesn't appear on the pop-up alert and only the captcha validation pop-up alert is being displayed when you inputted wrong captcha and when I don't input the correct fields but the captcha is correct the form submits..

 

here is my javascript code:

<script type="text/javascript">
	var url = '<?php echo tep_catalog_href_link('captcheck.php?code=');?>';
	var captchaOK = 2;  // 2 - not yet checked, 1 - correct, 0 - failed

	function getHTTPObject()
	{
	try {
	req = new XMLHttpRequest();
	  } catch (err1)
	  {
	  try {
	  req = new ActiveXObject("Msxml12.XMLHTTP");
	  } catch (err2)
	  {
	  try {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (err3)
		{
req = false;
		}
	  }
}
	return req;
}

	var http = getHTTPObject(); // We create the HTTP Object	  

	function handleHttpResponse() {
	if (http.readyState == 4) {
		captchaOK = http.responseText;
		if(captchaOK != 1) {
		  alert('The entered code was not correct. Please try again');
		  document.product_reviews_write.code.value='';
		  document.product_reviews_write.code.focus();
		  return false;
		  }
		  document.product_reviews_write.submit();
	   }
	}
   function checkcode(thecode) {
	http.open("GET", url + escape(thecode), true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
	}
function checkForm() {
 var error = 0;
 var error_message = "<?php echo JS_ERROR; ?>";
 // Now the Ajax CAPTCHA validation
 checkcode(document.product_reviews_write.code.value);
 return false;
 var review = document.product_reviews_write.review.value;
 var firstname = document.product_reviews_write.customers_firstname.value;
 var lastname = document.product_reviews_write.customers_lastname.value;
 var thecode = document.product_reviews_write.code.value;
 if (firstname.length < <?php echo ENTRY_FIRST_NAME_MIN_LENGTH; ?>) {
error_message = error_message + "<?php echo JS_FIRST_NAME; ?>";
error = 1;
 }
 if (lastname.length < <?php echo ENTRY_LAST_NAME_MIN_LENGTH; ?>) {
error_message = error_message + "<?php echo JS_LAST_NAME; ?>";
error = 1;
 }
 if (review.length < <?php echo REVIEW_TEXT_MIN_LENGTH; ?>) {
error_message = error_message + "<?php echo JS_REVIEW_TEXT; ?>";
error = 1;
 }
 if ((document.product_reviews_write.rating[0].checked) || (document.product_reviews_write.rating[1].checked) || (document.product_reviews_write.rating[2].checked) || (document.product_reviews_write.rating[3].checked) || (document.product_reviews_write.rating[4].checked)) {
 } else {
error_message = error_message + "<?php echo JS_REVIEW_RATING; ?>";
error = 1;
 }
 if (thecode.length < 4) {
error_message = error_message + "Please enter the code on the image.";
error = 1;
 }
 if (error == 1) {
alert(error_message);
return false;
 } else {
return true;
 }
}
</script>

 

Please help me coz i think im really close to this implementation.

Thank you.

 

Its okay now.. I solved the problem by myself.

Thanks.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...