我尝试过使用BootstrapValidator,但由于某种原因,除非我删除JS脚本,否则它不会提交表单。
JS脚本是:
$(document).ready(function() {
$('#loginForm').bootstrapValidator({
framework: 'bootstrap',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
email: {
validators: {
notEmpty: {
message: 'The email address is required'
},
emailAddress: {
message: 'The input is not a valid email address'
}
}
},
pass: {
validators: {
notEmpty: {
message: 'The password is required'
},
different: {
field: 'email',
message: 'The password cannot be the same as username'
}
}
},
}
});
});我的表格:
<div class="col-sm-4 col-sm-offset-5 col-md-4 col-md-offset-5 main">
<h1 class="page-header">Please sign in</h1>
<form id="loginForm" class="form-signin" action="ApplicantLogin.php" method="POST">
<label for="inputEmail" class="sr-only">e-Mail</label>
<input type="text" id="inputEmail" class="form-control" placeholder="e-Mail" name="email" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" name="pass" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" name="loginbtn" value="login">Sign in</button>
</form>
</div> <!-- /container -->正如创建者所建议的那样,我已经将按钮名更改为与默认值不同的名称,但仍然无法工作。知道为什么吗?不过,验证工作还不错。
发布于 2017-01-11 21:20:53
您的表单没有提交,因为您没有submit按钮。将type="submit"添加到其中。
<button type="submit" class="btn btn-lg btn-primary btn-block" name="loginbtn" value="login">Sign in</button>发布于 2017-01-11 22:15:45
我已经尝试过您在我的localhost和中提供的代码,它可以工作。我尝试在这里插入相同的小提琴,控制台显示了以下错误:
引导验证器不是一个函数。
由于某种原因,插件似乎没有加载。也许这就是你网络上发生的事。要解决这个问题,您可以链接引导程序验证程序库:
//cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.4.5/css/bootstrapvalidator.min.css
//cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.4.5/js/bootstrapvalidator.min.js如果验证器正在工作,它应该使用您拥有的按钮提交,如果单击空输入,它应该会显示一条消息。
https://stackoverflow.com/questions/41600408
复制相似问题