我的问题是,当我点击提交按钮时,表单已提交,但之前未经过验证。
通常当您单击“提交”按钮并且表单已经过验证并且仅在一切正常时发送
查看我的代码
<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
为什么在提交之前表单未经过验证和验证?
答案 0 :(得分:3)
没有内置函数忽略 - 删除它并且应该没问题
ddd: {
// ignore: ''
},