【发布时间】:2015-12-17 09:12:35
【问题描述】:
这是我的模态表单的 html 代码。
<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>';
}
}
无论如何我可以在我的模态表单中显示错误而不
关闭它?我也有这个ShowAlertWarning() 函数
它将以我的模态形式显示,而无需刷新我的页面。
【问题讨论】:
-
else{ $showWarning = true;显示警报警告(); session_destroy(); }
-
您必须为此使用
ajax。 1.将表单发送到服务器而不刷新。 2. 获取响应并将其放入您的模态中。如果您需要帮助,请联系我们。 -
在 Web 开发方面,我完全是一个新手。你能告诉我一些关于如何做到这一点的教程吗?
标签: javascript php jquery html twitter-bootstrap