开发者

jquery form validation issue

开发者 https://www.devze.com 2023-01-08 10:35 出处:网络
<script type=\"text/javascript\"> jQuery.validator.addMethod(\"steam_id\", function(value, element) {
<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开发者_如何学C 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


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() {


You can submit a form using jQuery by calling .submit();

Example: $("#form3").submit();

Reference: http://api.jquery.com/submit/

0

精彩评论

暂无评论...
验证码 换一张
取 消