Hello all,

I have a problem to validate my secureimage (CAPTCHA). Basically I have 3 pages of forms (formCheck.php, processForm.php and thankyou.php) - I have place this script in processForm.php -- This page only will display if the code was incorrect entered.

<?php
session_start();
require("include/application_top.php");
include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';

$securimage = new Securimage();
if ($securimage->check($_POST['captcha_code']) == false) {
   echo "The security code entered was incorrect.<br /><br />";
//exit;
//}
?>

The problem is: most of my error checking is in the first page (formCheck.php) which I'm using Javascript (Pop Up error messages) - And I would like the same goes to the CAPTCHA validate error message if someone entered a wrong code and will display and pop up on the first page as well. I heard that I need to use AJAX to build this? But I don't know how AJAX works. Can anyone please assist me?

This is one of my example of error msg which I place in formCheck.php:

This snippets will displayed if field is empty

$('[name=captcha_code]').parent().removeClass('error');
    if($('[name=captcha_code]').val()==""){
      error_num++;
      error_mesg += "Please enter the image verification\n";
      $('[name=captcha_code]').parent().addClass('error');
    }

This snippets (not working but this is what I want to achieve) will displayed if code entered is not match the code...


$('[name=captcha_code]').parent().removeClass('error');
   if ($securimage->check($_POST['captcha_code']) == false){
      error_num++;
      error_mesg += " The security code entered was incorrect \n";
      $('[name=captcha_code]').parent().addClass('error');
    }

Anyone please?

    First, if you actually need to use captcha, javascript is the worst way to validate form data. It takes no effort to bypass the javascript and submit directly to the php. So you must also validate all data in php.

    That said javascript does allow for a more user friendly approach to form validation. And to have the capthca validate in javascript you can use the AJAX technique. AJAX is javascript that is using the "XMLHttpRequest" (non-IE browsers) or "ActiveXObject" (for IE browsers) functions. I am sure if you do a search for those you will find several good examples and/or tutorials of how to use them.

    Lastly I would note that there is difference between Jquery and javascript, and unless you know Jquery really well just stick with javascript.

      Thanks Krik,

      I have use the CAPTCHA that is provided from this site: http://www.phpcaptcha.org/

      As I said the only thing that I need to add was the "error message" when incorrect code entered is displayed on the same page instead of the next page (Pop up message)

      I have look several example on-line but I could not find the one that I am looking for.

      Do you know any other source or could you help me how I can do this please?

      Thanks.

        Write a Reply...