当窗体之间发现一个封闭的div时,窗体不验证该字段 [英] Form does not validate a field when it finds a closed div inbetween

查看:80
本文介绍了当窗体之间发现一个封闭的div时,窗体不验证该字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery内联表单验证来验证我的表单.我的表单结构分为两列.第二列只是文本区域.而第一列包含其余字段.

I am using the jQuery inline form validation to validate my form. my form structure is such that it is split into two columns. the second column just have the text area. while the first column have the rest of the field.

这是我用于表单的代码.

here is the code that i am using for form.

<h1 class="com-response">Leave a reply for this Article</h1>
    <div class="com-respond">
        <div class="w340">
            <span class="com-label">Name</span>
                <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" id="formID">
                <input type="text" id="author" name="author" class="validate[required,custom[onlyLetter]]"/>
                <span class="com-label">email</span>
                <input type="text" id="email" name="email" class="validate[required,custom[email]]"/>
                <span class="com-label">Phone</span>
                <input type="text" id="phone" name="phone" class="validate[required,custom[telephone]]"/>
                <span class="com-label">Location</span>
                <input type="text" id="location" name="location" class="validate[required,custom[onlyLetter]]"/>
            </div>
        <div class="w340">
                <span class="com-label">Comment</span>
                <textarea rows="10" id="comment" name="comment" class="validate[required,length[6,300]]"></textarea>
                <input type="submit" value="Add Comment *" id="submit" name="submit"/>
                </form>
                <span class="title_sub">* your email and phone will be private and confidential by clicking on submit button you agree to our <a href="#">TOS</a></span>
        </div>
</div>

第一栏正在验证中,没有任何问题,但是第二栏我正面临着问题.即文本区域.

the first column is being validated without any problem , but i am facing the problem with the second column. i.e text area.

第一和第二列用名为w340的div包裹.并且在它们之间的形状元素w340被关闭并再次打开.结束股利造成了问题.如果我删除它,它也会验证textarea.但是在div关闭的情况下,它拒绝验证该字段.

the first and second column is wrapped with a div named w340. and in between the form element w340 is closed and opened again. the closing div is creating the problem. if i remove it, it validates the textarea too. but with the div closed it refuses to validate the field.

任何类型的帮助,我们都很感激.

any type of help is appreciated.

谢谢

这是我正在使用的jQuery 为此.

EDIT : Here is the jquery i am using for this.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
<script src="js/jquery.validationEngine-en.js" type="text/javascript"></script>
<script src="js/jquery.validationEngine.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$("#formID").validationEngine({
})  
});
</script>

这是我正在使用的插件的链接

here is the link to the plugin i am using

http://www.position-absolute.com/articles/jquery-form-validator-因为表单验证-is-a-mess/

推荐答案

您的文档格式不正确:您的表单在一个div内开始,而在另一个div内结束.将表单的开始和结束标签移动到两个div之外,如下所示:

Your document isn't well-formed: your form starts inside one div and ends in another. Move the form opening and closing tags outside of the two divs, like so:

<h1 class="com-response">Leave a reply for this Article</h1>
    <div class="com-respond">
        <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" id="formID">
            <div class="w340">
                <span class="com-label">Name</span>
                <input type="text" id="author" name="author" class="validate[required,custom[onlyLetter]]"/>
                <span class="com-label">email</span>
                <input type="text" id="email" name="email" class="validate[required,custom[email]]"/>
                <span class="com-label">Phone</span>
                <input type="text" id="phone" name="phone" class="validate[required,custom[telephone]]"/>
                <span class="com-label">Location</span>
                <input type="text" id="location" name="location" class="validate[required,custom[onlyLetter]]"/>
            </div>
            <div class="w340">
                <span class="com-label">Comment</span>
                <textarea rows="10" id="comment" name="comment" class="validate[required,length[6,300]]"></textarea>
                <input type="submit" value="Add Comment *" id="submit" name="submit"/>
                <span class="title_sub">* your email and phone will be private and confidential by clicking on submit button you agree to our <a href="#">TOS</a></span>
            </div>
       </form>
    </div>

尽管浏览器可能能够理解您的表单,但是按照您的方式做事实际上是非法的.但是,直到您尝试将HTML解析为DOM树,它才会显示出来-jQuery正是这么做的.您的表单节点不能部分生活在一个div节点中,而部分生活在另一个div节点中.

While the browser may be able to make sense of your form, it's actually illegal to do things the way you've done them. It won't show, though, until you try to parse the HTML into a DOM tree -- which is exactly what jQuery does. Your form node can't live partially in one div node and partially in another.

这篇关于当窗体之间发现一个封闭的div时,窗体不验证该字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆