使用验证码和 javascript 焦点更改

发布于 2024-10-21 14:48:13 字数 1900 浏览 1 评论 0原文

我有一个作为验证字段的表单,页面上显示一个 rand() 服务器变量,用户必须输入该代码才能完成成功的验证。当用户从该字段更改焦点时,脚本会打开一个 php 文件,该文件检查用户输入的代码与服务器代码的有效性。如果代码匹配,则会向用户显示提交表单的按钮,如果输入的代码不正确,则用户会收到错误消息。

<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").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('<input type="submit" value="Post Your Story"/>').addClass('messageboxok').fadeTo(900,1);    
        });
      }

    });

});
});
</script>

/////这就是 check.php 的样子\\\\

<?
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";
 }
?>

最后有输入字段

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

我需要一种方法来调整此脚本以与验证码验证工具一起使用。昨天我疯狂地收到垃圾邮件,我想要一种方法来调整此脚本以使用验证码实用程序,我希望验证脚本在焦点从验证码对象更改后运行。谢谢!

编辑:可以在此处查看所述表单的示例: http://www.mybadhookups.com/ist331.php

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").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('<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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一萌ing 2024-10-28 14:48:13

好的,我通过查看您的代码回答了我自己的问题。

在这里查看 Keith Woods 验证码的 jQuery 插件:http://keith-wood.name/realPerson.html

他甚至在选项卡上有服务器端代码:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文