2

我的问题是,当我单击提交按钮时,表单已提交但之前未经过验证。

通常当您单击提交按钮并且表单被验证并仅在一切正常时发送

查看我的代码

<form action="http://localhost/Localizze/auth/register.html" method="post" accept-charset="utf-8" id="singup-form" novalidate="novalidate">
        <fieldset>
            <div class="control-group">
                <div class="controls">
                    <input type="text" name="name" value="" class="input-block-level" id="name" placeholder="Digite seu nome">                    </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <input type="text" name="email" value="" class="input-block-level" id="email" placeholder="Digite seu email">                    </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <input type="password" name="password" value="" class="input-block-level" id="password" placeholder="Digite uma senha">                    </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <input type="password" name="confirmation_password" value="" class="input-block-level" id="confirmation_password" placeholder="Digite sua senha">                    </div>
            </div>
            <div class="control-group">
                <div class="controls">

               (<input type="text" name="ddd" value="" maxlength="2" class="input-ddd" id="ddd" placeholder="DDD">) <input type="text" name="celular" value="" maxlength="9" class="input-celular" id="celular" placeholder="Celular">                    
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <div class="input-prepend" style="width: 95%;margin-bottom: 20px;">
                        <span class="add-on">@</span><input type="text" name="twitter" value="" class="input-block-level" id="twitter" placeholder="Usuário do Twitter">                        </div>
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <label class="checkbox">
                        Entendo que o Localizze não é afiliado aos Correios e não pode resolver problemas sobre minha encomenda. <input type="checkbox" name="agree" value="1" id="agree" style="margin-top:-8px;">                        </label>
                </div>
            </div>
            <div class="form-actions">
                <button type="submit" class="btn btn-primary btn-large">Enviar</button>
                <button type="reset" class="btn btn-large">Cancelar</button>
            </div>
        </fieldset>
        </form>

JS

$(document).ready(function() {

$('#singup-form').validate(
        {
            rules: {
                name: {
                    minlength: 3,
                    required: true
                },
                email: {
                    required: true,
                    email: true
                },
                password: {
                    required: true
                },
                confirmation_password: {
                    required: true,
                    equalTo: '#password'
                },
                ddd: {
                    ignore: ''
                },
                celular: {
                    number: true,
                    minlength: 8
                },
                twitter: {
                    minlength: 3
                },
                agree: {
                    required: true
                }
            },
            highlight: function(label) {
                $(label).closest('.control-group').removeClass('success').addClass('error');
            },
            success: function(label) {
                label
                        .text('OK!').addClass('valid')
                        .closest('.control-group').removeClass('error').addClass('success');

            }
        });
}); // end document.ready

为什么表单在提交前没有经过验证和验证?

4

1 回答 1

3

没有内置函数忽略 - 删除它应该没问题

ddd: {
 // ignore: ''
},
于 2013-01-17T21:55:45.717 回答