Javascript 在模态引导中验证注册表单
我试图在模式框中验证我的签名表单,但每次我提交模式时都会关闭并刷新页面 我试图安装引导验证程序,但它不工作 此外,如果电子邮件是空的,仍然每次重新加载并关闭邮箱,我也无法收到错误消息Javascript 在模态引导中验证注册表单,javascript,php,jquery,twitter-bootstrap,validation,Javascript,Php,Jquery,Twitter Bootstrap,Validation,我试图在模式框中验证我的签名表单,但每次我提交模式时都会关闭并刷新页面 我试图安装引导验证程序,但它不工作 此外,如果电子邮件是空的,仍然每次重新加载并关闭邮箱,我也无法收到错误消息 <form id="IDofmyform" action="#" method="POST"> <div class="form-group"> <input type="text" name="reg_fullname" class="form-control-for
<form id="IDofmyform" action="#" method="POST">
<div class="form-group">
<input type="text" name="reg_fullname" class="form-control-form " id="exampleInputEmaillog" placeholder="Full Name" value="<?php
if(isset($_SESSION['reg_fullname'])){
echo $_SESSION['reg_fullname'];
}
?>">
<?php if(in_array('Your name is too long. Please include only firstname and lastname', $error_array)) echo 'Your name is too long. Please include only firstname and lastname';
else if(in_array('Please enter a valid name' , $error_array)) echo 'Please enter a valid name'; ?>
</div>
<div class="form-group">
<input type="email" name="reg_email" class="form-control-form " id="exampleInputEmaillog" placeholder="Email" value="<?php
if(isset($_SESSION['reg_email'])){
echo $_SESSION['reg_email'];
}
?>">
</div>
<div class="form-group">
<input type="email" name="reg_email2" class="form-control-form " id="exampleInputEmaillog" placeholder="Confirm Email" value="<?php
if(isset($_SESSION['reg_email2'])){
echo $_SESSION['reg_email2'];
}
?>">
<?php if(in_array('Email already in use', $error_array)) echo 'Email already in use';
else if(in_array('Invalid Email Format', $error_array)) echo 'Invalid Email Format';
else if(in_array('Emails do not match', $error_array)) echo 'Emails do not match'; ?>
</div>
<div class="form-group">
<input type="password" name="reg_password" class="form-control-form " id="exampleInputPasswordpas" placeholder="Password">
</div>
<div class="form-group">
<input type="password" name="reg_password2" class="form-control-form " id="exampleInputPasswordpas" placeholder="Confirm Password">
<?php if(in_array('Your passwords do not match', $error_array)) echo 'Your passwords do not match';
else if(in_array('Special characters like "£%^*() are not allowed', $error_array)) echo 'Special characters like "£%^*() are not allowed';
else if(in_array('Your password must be between 5 and 20 character', $error_array)) echo 'Your password must be between 5 and 20 character'; ?>
</div>
<div class="row">
<div class="col-md-12">
<div class="checkbox">
<label>
<input type="checkbox">I’d like to receive emails
</label>
</div>
</div>
</div>
<button type="submit" name="register_button" class="btn-lgin">Signup</button>
</form>
任何反馈都是有用的您的表单需要一个操作url
<form action="action_url" method="POST">
或者,如果您将数据发布在同一页上,请像这样使用
<form action="" method="POST">
您需要通过添加onclick处理程序来捕获提交按钮上的click事件。使用jQuery,您可以这样做:
$("<button selector>").click(function(){
<handler code>
});
$(“”)。单击(函数(){
});
在处理程序中,调用preventDefault()
,以使提交操作不发生。您还可以调用stopPropagation()
然后验证表单并在表单上调用submit,或者如果一切正常,可以使用登录数据触发ajax请求。或者,如果没有,则在模式中显示错误消息。No@Raushan我试过了。我的表单在模态框中,这就是为什么我认为它不起作用。你在控制台上有错误吗?
$("<button selector>").click(function(){
<handler code>
});