简体   繁体   English

我的jQuery表单验证不起作用

[英]My jQuery form validation isn't working

I'm trying to make this piece of code work. 我正在尝试使这段代码起作用。 But there is something wrong with it. 但是这有问题。 I don't know what. 我不知道 Anyone care to help here. 任何人都希望在这里提供帮助。 Thanks The problem is that when the form is submitted and it doesn't show any validation messages. 谢谢!问题是,提交表单时,它不显示任何验证消息。

<?php
session_start();
include 'connection.php';
if(isset($_POST['submit'])){
$name=$_POST['name'];
$f_name=$_POST['f_name'];
$cell=$_POST['cell_no'];
$_SESSION['name']=$name;
$_SESSION['f_name']=$f_name;
$_SESSION['cell']=$cell;



}

?>
<html>

<head>
    <script src="jquery-1.3.1.min.js">
    </script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
    </script>
    <script type="text/javascript"></script>
    <script>
    $(document).ready(function() {
        $("#myForm").validate({

            rules: {
                name: "required",
                f_name: "required",
                cell_no: {
                    required: true,
                    minlenght: 11
                }
            },
            messages: {
                name: "Please state your name.",
                f_name: "Father name is required.",
                cell_no: {
                    required: "Please provide a contact number.",
                    minlength: "Minimum length is 11 digits"
                }
            },
            submitHandler: function(form) {
                form.submit();
            }

        });

    });
    </script>
</head>

<body>
    <center>

<?php  
echo @$_GET['sheikh'];    
?>
</center>


<form method="POST" action="" id="myForm" novalidate="novalidate">
<center><h1>First Form</h1></center>
<h2>Basic Information</h2>
Name:<input type="text" name="name">
Father name:<input type="text" name="f_name">
Cell_no:<input type="text" name="cell_no">
<input type="submit" name="submit" value="next">
</form>
</body>

</html>

Problems in your script: 脚本中的问题:

  1. You have included jQuery twice on the page 您已在页面上两次包含jQuery
  2. You haven't included jQuery.validate.js 您尚未包含jQuery.validate.js

Please try checking the console log when you have this kind of issues. 遇到此类问题时,请尝试检查控制台日志。 You will come to know what is the problem. 您将了解问题所在。

when the page loads it shows, 当页面加载时显示

"Uncaught TypeError: $(...).validate is not a function" “未捕获的TypeError:$(...)。validate不是函数”

this means the required library not exists with you code. 这意味着所需的库与您的代码不存在。 Download it and insert in your page like 下载并插入您的页面,例如

script src="jquery-1.3.1.min.js" 脚本src =“ jquery-1.3.1.min.js”

you did or give direct link if you doing this for learning purpose. 您出于学习目的而这样做或给出直接链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM