jquery表单验证问题
<script type="text/javascript">
jQuery.validator.addMethod("steam_id", function(value, element) {
return this.optional(element) || /^STEAM_0:(0|1):[0-9]{1}[0-9]{0,8}$/.test(value);
});
jQuery.validator.addMethod("nome", function(value, element) {
return this.optional(element) || /^[a-zA-Z0-9._ -]{4,16}$/.test(value);
});
$().ready(function() {
var validator = $("#form3").bind("invalid-form.validate", function() {
$("#summary").html("O formulário contém " + validator.numberOfInvalids() + " erros.");
}).validate({
debug: true,
errorElement: "em",
errorContainer: $("#warning, #summary"),
errorPlacement: function(error, element) {
error.appendTo(element.parent("td").next("td"));
},
success: function(label) {
label.text("").addClass("success");
},
rules: {
steamid: {
required: true,
steam_id: true
},
username: {
required: true,
nome: true
},
nickname: {
required: true,
nome: true
},
}
});
});
</script>
好吧,我的问题是,如何将此表单提交到 php.ini。我想在数据库中插入一个东西,并且我有一个 phpscript 用于此操作,但是通过此验证我无法做到这一点。
你能告诉我如何使用jquery提交吗?
我正在使用 bassitance 的 jquery 验证插件
<script type="text/javascript">
jQuery.validator.addMethod("steam_id", function(value, element) {
return this.optional(element) || /^STEAM_0:(0|1):[0-9]{1}[0-9]{0,8}$/.test(value);
});
jQuery.validator.addMethod("nome", function(value, element) {
return this.optional(element) || /^[a-zA-Z0-9._ -]{4,16}$/.test(value);
});
$().ready(function() {
var validator = $("#form3").bind("invalid-form.validate", function() {
$("#summary").html("O formulário contém " + validator.numberOfInvalids() + " erros.");
}).validate({
debug: true,
errorElement: "em",
errorContainer: $("#warning, #summary"),
errorPlacement: function(error, element) {
error.appendTo(element.parent("td").next("td"));
},
success: function(label) {
label.text("").addClass("success");
},
rules: {
steamid: {
required: true,
steam_id: true
},
username: {
required: true,
nome: true
},
nickname: {
required: true,
nome: true
},
}
});
});
</script>
Well, my question is, how do I submit this form to php. I want to insert a thing in a databse and I have a phpscript for that, but with this validation I can't do that.
Can you tell me how submit using jquery?
I'm using the jquery validation plugin from bassitance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题就在这里:
当您具有
debug
属性 设置为true
,它会主动阻止表单提交...用于调试,因此您可以测试验证规则但永远不会触发回发。它纯粹用于测试。一旦您按照自己想要的方式进行了验证,并且想要实际提交表单(您现在所在的位置!),请删除debug
设置(或将其设置为false< /代码>)。
附带说明一下,
$().ready(function() {
在 jQuery 1.4+ 中已弃用,您应该使用其中之一:The problem is here:
When you have the
debug
property set totrue
, it actively prevents form submission...for debugging, so you can test your validation rules but never trigger a postback. It's purely for testing. Once you've got validation how you want it and you want to move to actually submitting the form (where you're at!), remove thedebug
setting (or set it tofalse
).As a side note,
$().ready(function() {
is deprecated in jQuery 1.4+, instead you should use one of these:您可以通过调用 .submit() 使用 jQuery 提交表单;
示例: $("#form3").submit();
参考: http://api.jquery.com/submit/
You can submit a form using jQuery by calling .submit();
Example: $("#form3").submit();
Reference: http://api.jquery.com/submit/