weixin_33720956 2014-11-27 11:11 采纳率: 0%
浏览 66

在弹出窗口中进行表单验证

Am Working on LOGIN form in a popup.. when form submitted it is returning to validations and displaying errors but i want to compare with database with in the pop up and display error message if login and password not matched for this i had tried with ajax to get the email and password compared with DB..

JS:

function login_validation(){ 
    //worked with some validations like empty string and email filter...they are working fine displaying errors                                     
    $(document).ready(function(){
        $("#upwd").on("focusout",function(){
            var uemail = $("#uemail").val();
            var upwd = $("#upwd").val();

            $.ajax({
                type: "POST",
                url: "checkl_login.php",
                data: 'uemail='+uemail+'&upwd='+upwd,
                success: function(msg){
                $('#status').html(msg);
                    return false;   
                } 
            });
        }); 
    });
}

HTML:

<form name="f" method="POST"  action='' onsubmit="return login_validation()">

<p><input type="text"  placeholder="Email"  name="uemail"  id="uemail"  > </p><span id="uemailerror"></span>


<p><input type="password"  placeholder="password"  name="upwd"  id="upwd" ><span id="upassworderror"></span><span id="status"></span>

<!--submit button.. -->

PHP, checkl_login.php:

ob_start();

session_start();

include('dbconnect.php'); 

include('gettime_diff.php');  

mysql_select_db("hccommunity") or die(mysql_error()); 

if($_POST['uemail'] && $_POST['upwd']){

    $loginemail = mysql_escape_string($_POST['uemail']);  

    $loginpwd = mysql_escape_string($_POST['upwd']); 

    $search = mysql_query("SELECT * FROM user WHERE email='".$loginemail."' AND password='". mysql_escape_string(md5($loginpwd)) ."'") or die(mysql_error());   

    $match  = mysql_num_rows($search);  

    if($match > 0){  
        echo "OK";
    }

    else{
        echo "ERROR";
    }
}

the form is not displaying the "error" or "ok" message....

  • 写回答

1条回答 默认 最新

  • weixin_33735077 2014-11-27 11:32
    关注

    Replace/remove your login_validation() function with the following code.

    $(document).ready(function(){
        $("form").on("submit",function(e){
    
            var uemail = $("#uemail").val();
            var upwd = $("#upwd").val();
            e.preventDefault();
            $.ajax({
                type: "POST",
                url: "checkl_login.php",
                data: 'uemail='+uemail+'&upwd='+upwd,
                success: function(msg){
                $('#status').html(msg);
                    return false;   
                } 
            });
        }); 
    });
    

    And replace the form tag with this

    <form name="f" method="POST" action=''>

    评论

报告相同问题?

悬赏问题

  • ¥15 stc15f2k60s2单片机关于流水灯,时钟,定时器,矩阵键盘等方面的综合问题
  • ¥15 YOLOv8已有一个初步的检测模型,想利用这个模型对新的图片进行自动标注,生成labellmg可以识别的数据,再手动修改。如何操作?
  • ¥30 NIRfast软件使用指导
  • ¥20 matlab仿真问题,求功率谱密度
  • ¥15 求micropython modbus-RTU 从机的代码或库?
  • ¥15 django5安装失败
  • ¥15 Java与Hbase相关问题
  • ¥15 后缀 crn 游戏文件提取资源
  • ¥20 bash代码推送不上去 git fetch origin master #失败了
  • ¥15 LOL外服加入了反作弊系统,现在游戏录像rofl文件离线都无法打开