开发者

using captcha with javascript focus change

开发者 https://www.devze.com 2023-02-17 05:43 出处:网络
I have a form that is a validation field, there is a rand() server variable that displays on the page, the user has to type that code in to complete a successful validation. When the user changes focu

I have a form that is a validation field, there is a rand() server variable that displays on the page, the user has to type that code in to complete a successful validation. When the user changes focus from this field, a script opens a php file that checks the validity of the code the user has entered with the server code. If the code matches, the user is shown a button to submit the form, if the code is entered incorrectly, the user gets an error message.

<script language="javascript">

$(document).ready(function()
{
$("#usercode").blur(function()
{
    //remove all the class add the messagebox classes and start fading
        $("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
    //check the username exists or not from ajax
    $.post("check.php",{ usercode:$(this).val() } ,function(data)
    {
      if(data=='no') //if username not avaiable
      { 
        $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
        {//alert(data);
          //add message and change the class of the box and start fading
          $(this).html('Your code was incorrect').addClass('messageboxerror') .fadeTo(900,1);
        });     
      }
      else
      {
        $("#msgbox").fa开发者_C百科deTo(200,0.1,function()  //start fading the messagebox
        {// alert(data);
          //add message and change the class of the box and start fading
          $(this).html('<input type="submit" value="Post Your Story"/>').addClass('messageboxok').fadeTo(900,1);    
        });
      }

    });

});
});
</script>

/////this is what check.php looks like\\\\

<?
session_start();

$sescode= $_SESSION['code'];
$usercode = $_POST['user_name'];

if ($sescode==$usercode) {
// What happens when valid
echo("yes");
} else {
// what happens when invalid
 echo "no";
 }
?>

finally there is the input field

<input type="text" id="usercode" name="usercode" />

I need a way to adapt this script to work with the captcha validation tool. I was spammed like crazy yesterday, and I would like a way to adapt this script to use the captcha utility, I would like the validation script to run after the focus is changed from the captcha object. Thanks!

edit: an example of said form can be viewed here: http://www.mybadhookups.com/ist331.php


OK, I answered my own question by looking at your code.

Look at Keith Woods jQuery plugin for captcha here: http://keith-wood.name/realPerson.html

He even has the server side code on the tab for that :)

0

精彩评论

暂无评论...
验证码 换一张
取 消