jquery表单验证问题

发布于 2024-09-10 11:14:39 字数 1541 浏览 2 评论 0原文

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

油饼 2024-09-17 11:14:39

The problem is here:

debug: true,

When you have the debug property set to true, 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 the debug setting (or set it to false).

As a side note, $().ready(function() { is deprecated in jQuery 1.4+, instead you should use one of these:

$(document).ready(function() {
//or:
$(function() {
廻憶裏菂餘溫 2024-09-17 11:14:39

您可以通过调用 .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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文