Javascript 模式表单在提交时显示错误并阻止其关闭
这是我的模态表单的html代码Javascript 模式表单在提交时显示错误并阻止其关闭,javascript,php,jquery,html,twitter-bootstrap,Javascript,Php,Jquery,Html,Twitter Bootstrap,这是我的模态表单的html代码 <form action="" class="cd-form" method="POST" id="signinform" onsubmit="return: false;"> <p class="fieldset" id="warningPanel"> <?php ShowAlertWarning(); ?> </p> <p class="fieldset">
<form action="" class="cd-form" method="POST" id="signinform" onsubmit="return: false;">
<p class="fieldset" id="warningPanel">
<?php ShowAlertWarning(); ?>
</p>
<p class="fieldset">
<label class="image-replace cd-username" for="signin-username">Username</label>
<input class="full-width has-padding has-border" id="signin-username" name="login_username" type="text" placeholder="Username" required>
<span class="cd-error-message">Error message here!</span>
</p>
<p class="fieldset">
<label class="image-replace cd-password" for="signin-password">Password</label>
<input class="full-width has-padding has-border" id="signin-password" name= "login_password" type="password" placeholder="Password" required>
<span class="cd-error-message">Error message here!</span>
</p>
<div id="remember">
<p class="fieldset">
<input type="checkbox" id="remember-me" >
<label for="remember-me">Remember me</label>
</p>
</div>
<input class="full-width" type="submit" name="login" value="Login" id="signin_button">
</form>
用户名
这里有错误信息!
密码
这里有错误信息!
记得我吗
这也是我的php代码
if(isset($_POST['login'])){
$username = stripslashes($_POST['login_username']);
$password = stripslashes($_POST['login_password']);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql = "SELECT user.userID, user.password, profile.firstname FROM user, profile WHERE username = '$username' AND user.userID = profile.userID";
$result = $con->query($sql);
if($result->num_rows > 0){
while($row = $result->fetch_assoc()){
$chk_password = $row['password'];
$chk_firstname = $row['firstname'];
$userID = $row['userID'];
$_SESSION['userID'] = $userID;
if(password_verify($password, $chk_password)){
$_SESSION['username_logged_in'] = true;
if(empty($chk_firstname))
header('Location: profile.php');
else
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
}
}
else{
$showWarning = true;
session_destroy();
}
}
function ShowAlertWarning(){
global $showWarning;
$newShowWarning = $showWarning;
if($newShowWarning){
echo '<div class="alert alert-dismissible alert-danger form-feedback">';
echo '<button type="button" class="close" data-dismiss="alert">x</button>';
echo '<strong>Oh snap!</strong> Wrong username or password, please try again.';
echo '</div>';
}
}
if(isset($\u POST['login']){
$username=stripslashes($\u POST['login\u username']);
$password=stripslashes($\u POST['login\u password']);
$username=mysql\u real\u escape\u字符串($username);
$password=mysql\u real\u escape\u字符串($password);
$sql=“从用户中选择user.userID、user.password、profile.firstname,其中username='$username'和user.userID=profile.userID”;
$result=$con->query($sql);
如果($result->num_rows>0){
而($row=$result->fetch_assoc()){
$chk_password=$row['password'];
$chk_firstname=$row['firstname'];
$userID=$row['userID'];
$\会话['userID']=$userID;
如果(密码验证($password,$chk_password)){
$\u会话['username\u logged\u in']=true;
if(空($chk_firstname))
标题('Location:profile.php');
其他的
标题('Location:'.$\u服务器['HTTP\u REFERER']);
}
}
}
否则{
$showWarning=true;
会话_destroy();
}
}
函数ShowAlertWarning(){
全球$showWarning;
$newShowWarning=$showWarning;
如果($newShowWarning){
回声';
回声“x”;
回显“哦,快照!用户名或密码错误,请重试。”;
回声';
}
}
我是否可以在模态表单中显示错误,而不显示错误
关闭它?我还有一个ShowAlertWarning()
函数
它将以我的模式形式显示,而不刷新我的页面。关闭提交按钮。这就是关闭表单的原因。然后添加到输入
onclick=“yourCustomFunctionHere()”
并使用JS编写一个函数,该函数将检查字段是否为空,并仅在字段全部满时提交。否则{$showWarning=true;ShowAlertWarning();session_destroy();}必须使用此函数。1.将表单发送到服务器而不刷新。2.获取响应并将其放入您的模式中。如果你需要帮助,请告诉我们。我在网络开发方面完全是个新手。你能给我看一些如何做的教程吗?