【发布时间】:2021-05-25 18:48:47
【问题描述】:
尝试在表单内成功登录后隐藏登录表单,以便用户登录后无法看到该表单,但我仍然需要在成功时显示成功消息登录已经发生。 我对表单和登录名进行了排序,成功登录后显示成功消息,但成功登录后我无法隐藏表单。 我有一个使用 isset 设置的 if 语句,但据我所知,我不知道在 if 语句中需要做什么才能隐藏表单。
这是我的登录页面的 PHP 代码 -
<?php
require('includes/application_top.php');
$page_title='Login!';
if (isset($_POST['action'])) {
$username_input = $_POST['username'];
$password_input = $_POST['password'];
$login_ok = login($username_input, $password_input);
}
require('includes/site_header.php');
?>
<style>
<?php
require('css/login.css');
?>
</style>
<br>
<br>
<br>
<?php
if (isset($login_ok)) {
?>
<div class="row">
<div class="col-sm-12">
<?php
if ( ! $login_ok) {
?>
<div class="alert alert-danger">
<p>Your credentials were invalid</p>
</div>
<?php
} else {
?>
<div class="alert alert-success">
<p>Login successful</p>
</div>
<?php
}
?>
</div>
</div>
<?php
}
?>
<!-- This is the if statement I mention -->
<?php
if !isset($login_okay){
?>
<div class="wrapper dafswInDown" hidden>
}
?>
<div class="wrapper fadeInDown">
<div id="formContent">
<!-- Icon -->
<div class="fadeIn first">
<br>
<img src="images/Head1.jpg" style="height: 40%; width: 60%;" id="icon" alt="User Icon" />
<br>
<h3> Login! </h3>
</div>
<br>
<!-- Login Form -->
<form id="login_form" action="login_page.php" method="post">
<input type="text" class="fadeIn second" id="username" name="username" placeholder="Username" value="<?= isset($_POST['username']) ? htmlspecialchars($_POST['username']) : '' ?>" maxlength="100" />
<input type="password" class="form-control" id="password" name="password" placeholder="Password" value="" />
<input type="submit" class="fadeIn fourth" name="action" value="Login"/>
</form>
<!-- Remind Passowrd -->
<div id="formFooter">
<a class="underlineHover" href="#">Forgot Password?</a>
</div>
</div>
</div>
<?php
require('includes/application_bottom.php');
require('includes/site_footer.php');
?>
【问题讨论】:
-
@bromber 这可能是错误的,就像我在被卡住之前所做的那样
-
@brombeer 是的,应该有括号我现在已经改变了
-
你的方法有什么不适用的?要么像你一样使用开头的
<div>(记得在你的表单之后使用相同的if关闭它)或者将你的完整表单放在if中,这样它就不会被渲染。 -
页面没有加载我现在拥有的内容,会将整个 div 放入 if 语句中
-
还要注意命名东西,你在上面使用
$login_ok,但在if中使用$login_okay