Javascript Jquery验证插件+;php操作不起作用

Javascript Jquery验证插件+;php操作不起作用,javascript,php,jquery,forms,validation,Javascript,Php,Jquery,Forms,Validation,我正在使用jqueryvalidate插件,但它没有为我启动,我在我的php表单上有一个操作,它允许我处理图像,并将其余信息发送到数据库。这是我的代码,如有任何帮助,将不胜感激。我让它停止提交,所以它根本没有重定向。我需要它来检查值,如果它都好,然后启动操作 <form name="form2" enctype="multipart/form-data" method="post" action="upload.php" id="newProject"/>

我正在使用jqueryvalidate插件,但它没有为我启动,我在我的php表单上有一个操作,它允许我处理图像,并将其余信息发送到数据库。这是我的代码,如有任何帮助,将不胜感激。我让它停止提交,所以它根本没有重定向。我需要它来检查值,如果它都好,然后启动操作

 <form name="form2" enctype="multipart/form-data" method="post" action="upload.php" id="newProject"/>
            <div class="inputs">
              <p>
                <span class="required"></span>
                <input type="text" name="title" placeholder="Title:" value="Title of Image"  />
                <small>This is the <strong>Title</strong> of the image.</small>
              </p>
              <p>
                <span class="required"></span>
                <input type="text" name="description" placeholder="Description:" value="Description"  />
                <small><strong>Description</strong> is shortened on main pages but will be fully displayed on the <strong>Single page</strong></small>
              </p>
              <p><span class="required"></span>
                <input class="checkBox" type="checkbox" name="category" value="1">Landscape<br />
              <span class="required"></span>
                <input class="checkBox" type="checkbox" name="category" value="2">Portrait<br />
              <span class="required"></span>
                <input class="checkBox" type="checkbox" name="category" value="3">Monochrome<br />
                <small></small>
              </p>
              <p><span class="required"></span>
              <input class="uploadFile" type="file" size="32" name="my_field" value=""  />
              <input type="hidden" name="action" value="image" /></p>
              <div class="actions">                     
              <p><button class="button" id="update_profile" value="upload">Upload</button></p>
              </div>
            </div>
         </form>


<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>

<script>
$(function() {
   $( "#newProject" ).validate({
rules: {
       title: {
               required: true,
               minlength: 4,
               maxlength: 20
       }
       description: {
               required: true,
               minlength: 20,
               maxlength: 500
       }
},
       messages: {
            title: {
               required: "Enter a title",
               minlength: $.format("Keep typing, at least {0} characters required!"),
               maxlength: $.format("Whoa! Maximum {0} characters allowed!")
            }
            description: {
               required: "Enter a description",
               minlength: $.format("Keep typing, at least {0} characters required!"),
               maxlength: $.format("Whoa! Maximum {0} characters allowed!")
            }
       }
   });
});  
</script> 

<script>
$(function(){


$("#newProject").on('submit', function(e){
    var isvalidate=$("#newProject").valid();
    if(isvalidate)
    {
        e.preventDefault();
        alert(getvalues("newProject"));
    }
});

});

function getvalues(f)
{
    var form=$("#"+f);
    var str='';
    $("input:not('input:submit')", form).each(function(i){
        str+='\n'+$(this).prop('title')+': '+$(this).val();
    });
    return str;
} 
</script>


这是图像的标题。

说明在主页上缩短,但在单页上完全显示

景观
肖像画
单色

上传

$(函数(){ $(“#新建项目”).validate({ 规则:{ 标题:{ 要求:正确, 最小长度:4, 最大长度:20 } 说明:{ 要求:正确, 最小长度:20, 最大长度:500 } }, 信息:{ 标题:{ 必填:“输入标题”, minlength:$.format(“保持键入,至少需要{0}个字符!”), maxlength:$.format(“哇!允许的最大字符数为{0}!”) } 说明:{ 必需:“输入说明”, minlength:$.format(“保持键入,至少需要{0}个字符!”), maxlength:$.format(“哇!允许的最大字符数为{0}!”) } } }); }); $(函数(){ $(“#新项目”)。关于('submit',函数(e){ var isvalidate=$(“#新项目”).valid(); 如果(isvalidate) { e、 预防默认值(); 警报(获取值(“新项目”); } }); }); 函数getvalues(f) { 变量形式=$(“#”+f); var-str=''; $(“输入:不('input:submit'),表单)。每个(函数(i){ str+='\n'+$(this.prop('title')+':'+$(this.val(); }); 返回str; }
试试这个

$(function() {
   $( "#newProject" ).validate({
rules: {
       title: {
               required: true,
               minlength: 4,
               maxlength: 20
       },
       description: {
               required: true,
               minlength: 20,
               maxlength: 500
       }
},
       messages: {
            title: {
               required: "Enter a title",
               minlength: $.format("Keep typing, at least {0} characters required!"),
               maxlength: $.format("Whoa! Maximum {0} characters allowed!")
            },
            description: {
               required: "Enter a description",
               minlength: $.format("Keep typing, at least {0} characters required!"),
               maxlength: $.format("Whoa! Maximum {0} characters allowed!")
            }
       }
   });
});  

您需要在每个规则和消息后添加逗号

Nop,nothing它会直接发送到promp,并带有所有值no validation whatsoeverdid您是否用上面的代码替换代码?我在我的机器上检查过了。哦,等等!!它现在起作用了。。。太棒了,唯一的一步是如何让它提交到操作,而不是删除提交提示所需的提示。。谢谢你的帮助