首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >成功提交时隐藏登录表单

问成功提交时隐藏登录表单
EN

Stack Overflow用户
提问于 2021-02-20 04:45:00
回答 1查看 24关注 0票数 1

我正在建设一个电子商务网站,有一个登录页面,登录页面的工作,并给出一个成功或错误的信息取决于是否正确的登录细节,并在需要时重置表单。但我需要该表单成为隐藏时,成功登录发生了。我知道我需要一个带有PHP标记的if语句,但这是我目前所能做到的。

这是代码

代码语言:javascript
复制
    <?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
        }
        ?>
<?php 
      if (isset(! $login_okay)) {
        ?>
        <
      }
<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');
?>
EN

回答 1

Stack Overflow用户

发布于 2021-02-20 05:12:09

代码语言:javascript
复制
Assuming your setting $login_ok = 1 for a pass and $login_ok = 0 for a fail.     



   <?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); // 1 for ok 0 for failed
}
require('includes/site_header.php');
?>
<style>
<?php
//require('css/login.css');
?>
</style>
<?php
// Part one Create login form 

// Store posted username incase of error 
$insertonfail=isset($_POST['username']) ? htmlspecialchars($_POST['username']) : '';
// Create form 
$loginform="
<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=\"$insertonfail\" 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>";
// Check for a login or display form 
if (!isset($login_ok))
    {
    echo $loginform;
    }
// 
if (isset($login_ok))
    {
        // Check passed         
        if ($login_ok == 1)
        {
        echo "<div class=\"row\">
                <div class=\"col-sm-12\">
                <div class=\"alert alert-success\">
                 <p>Login successful</p>
                 </div></div></div>";               
        }           
        // Check Failed  
        if ($login_ok == 0)
          {   
          echo "<div class=\"row\">
                <div class=\"col-sm-12\"><div class=\"alert alert-danger\">
                            <p>Your credentials were invalid</p>
                          </div></div></div>";      
                          
            echo $loginform;                    
          }     

        
    }
echo "</div>";

?>

<?php
require('includes/application_bottom.php');
require('includes/site_footer.php');
?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66284759

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档