简体   繁体   English

提交表单时的jQuery表单验证问题

[英]Jquery form validation issue when submitting form

I am attempting to create a registration form that uses jquery for validation. 我正在尝试创建一个使用jquery进行验证的注册表单。 When i click submit it doesnt seem to be working, it just lets me add anything into my Database even if there are missing fields or the passwords arent matching. 当我单击“提交”时,它似乎无法正常工作,它只允许我将任何内容添加到数据库中,即使缺少字段或密码也不匹配。

I have created a fiddle any help would be greatly appreciated. 我创造了一个小提琴,任何帮助将不胜感激。

http://jsfiddle.net/U8dGW/5/ http://jsfiddle.net/U8dGW/5/

if(username == "") {
    $("span.val_username").html("This field is required".).addClass('validate');
    validation_holder = 1;
} else {
    $("span.val_username").html("");
}

if(name == "") {
     $("span.val_name").html("This field is required".).addClass('validate');
    validation_holder = 1;
} else {
    $("span.val_name").html("");
}

Thank you 谢谢

Firstly it seems that your form is submitting because you haven't overriden the onsubmit event so basically you need to put in the form opening tag: 首先,您的表单似乎正在提交,因为您尚未覆盖onsubmit事件,因此基本上您需要在表单中添加开始标签:

onsubmit="return false;"

this will prevent the form from submitting automatically.. now you need to fix the validation method.. 这将阻止表单自动提交。.现在,您需要修复验证方法。

I fixed most of the bugs here.. you need to look at the validation process itself. 我在这里修复了大多数错误。您需要查看验证过程本身。

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

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