如果发生验证错误,请阻止启动窗体打开
Prevent Bootstrap Form from opening if validation error occurs
我正在使用引导程序和代码点火器创建一个注册表单。
流程:当有人注册时,会出现一个模式,要求提供OTP(一次性密码)。在未输入OTP之前,模态应保持打开状态。
这是我能够做到的。
问题如果注册表单有验证错误,我希望模态不应该出现。只有在注册表格中没有验证错误的情况下,模式才会弹出。
目前发生的情况是,即使我将注册表单留空,然后单击提交按钮,验证错误也会出现在后台,但模态也会弹出。我该如何防止这种情况发生。
附言:只有在表单得到验证后才会生成OTP,因此这不会成为问题。
代码:注册表格:
<div class="modal fade bs-example-modal-sm" id="myModal" role="dialog">
<div class="modal-dialog modal-sm">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Your OTP number is sent on your register mobile number</h4>
<div id="wrong_otp" style="color:red">
<h4 class="modal-title">Your OTP number does not match!!!</h4>
</div>
</div>
<div class="modal-body">
<div class="tab-pane active in" id="login">
<form id="otp" action="" method="post" enctype="multipart/form-data">
<div class="ptop-10"></div>
<div class="col-md-12">
<input type="text" class="signup" value="" placeholder=" Please Enter OTP Number" name="otp" id="otp" required="required">
<br />
<input type="hidden" class="signup" value="" name="otp_email" id="otp_email">
<br />
<input type="hidden" class="signup" value="" name="otp_password" id="otp_password">
<br />
<div class="ptop-10"></div>
<div class="ptop-5"></div>
</div>
<div class="ptop-10">
<div class="ptop-5"></div>
<center><button type="submit" class="btn btn-musturd">Submit</button></center>
</div>
</form>
</div>
</div>
<div class="modal-footer">
</div>
</div>
OTP模式的代码:
<!--for individual register-->
$("#individual").submit(function(event){
var email = $("#email").val();
// alert(email);
var pass = $("#password").val();
$("#otp_email").val(email);
$("#otp_password").val(pass);
$("#wrong_otp").hide();
// cancels the form submission
event.preventDefault();
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>index.php/signup",
data:$(this).serialize(),
success : function(text){
// event.preventDefault();
if (text==1 ){
// $("#view_preview").click(); //place this code
// window.location.href="<?php echo base_url(); ?>index.php/signup/myaccount";
}
else
{
// $("#wrong_otp").show();
}
}
});
});
function formSuccess(){
//$("#view_preview").click(); //place this code
}
<!--for individual register-->
<!--for individual register-->
$("#otp").submit(function(event){
$("#wrong_otp").hide();
// cancels the form submission
event.preventDefault();
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>index.php/signup/otp_check",
data:$(this).serialize(),
success : function(data){
alert(data);
if (data=='ok' ){
$("#myModel").hide();
window.location.href="<?php echo base_url(); ?>index.php/signup/myaccount";
}
else
{
$("#wrong_otp").show();
}
}
});
});
<!--function formSuccess(){
//$('#myModal').modal('show');
//$('#myModal').modal('toggle');
//$('#myModal').modal('show');
// $( "#msgSubmit" ).removeClass( "hidden" );
//}-->
<!--for individual register-->
</script>
您可以尝试自己验证表单,并使用验证成功/失败来显示OTP模式。。
$("#individual").submit(function(e){
var email = $("#email").val();
var pass = $("#password").val();
$("#otp_email").val(email);
$("#otp_password").val(pass);
$("#wrong_otp").hide();
// cancels the form submission
event.preventDefault();
// Do your validation here
if(myValidateFunc(email, password) == true) //success
{
//post the data using ajax
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>index.php/signup",
data:$(this).serialize(),
success : function(){
}
});
// Display the otp modal
$("modalDiv").modal("show");
// modify #modalDiv according to name of your otp modal
}
else
{
// Display validation errors
}
});
相关文章:
- 防止Iframe窗体在新窗口中打开
- 我的jQuery插件参数没有正确启动,遇到了问题
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- 从控制器返回后Ajax启动事件激发
- Meteor-将选定窗体中的对象添加到集合中
- Meteor上的启动页面
- 如何防止网页加载后自动启动功能
- 如何在窗体打开时从javascript倒计时计时器值中节省时间
- 如何从JavaScriptInterface启动Navigation Drawer
- 主干窗体隐藏字段未呈现
- window.on.scroll事件未启动
- 如何首先设置样式<td>表中包含在窗体中的元素
- 单击按钮后启动javascript提示
- 如何添加CSS&JavaScript进入Windows窗体应用程序C#.net
- 如何将窗体的子元素居中
- 在javaservlet doPost方法中启动线程时,无法返回异常消息
- 如果发生验证错误,请阻止启动窗体打开
- ASP页面窗体操作不允许ASP按钮单击启动
- 窗体按钮事件未启动
- 从Web窗体在客户端计算机上启动MS Word应用程序.(所有浏览器)