PHP Show Hidden Div

时间:2015-06-03 15:57:01

标签: javascript php html css

这是我的代码:

<?php
require_once("include/membersite_config.php");
if(isset($_POST['submitted']))
{
if($fgmembersite->Login())
{
$fgmembersite->RedirectToURL("login-home.php");
}
}
?>

<script>
window.onload = function() {
function validate(e) {
var username = document.getElementById('username');
if (username.value.trim() == '') {
username.style.backgroundColor = '#ff4c4c';
e.preventDefault();
} else {
username.style.backgroundColor = null;
}
var password = document.getElementById('password');
if (password.value.trim() == '') {
password.style.backgroundColor = '#ff4c4c';
e.preventDefault();
}else {
password.style.backgroundColor = null;
}
}
document.getElementById('login').addEventListener('submit', validate);
}
</script>

<div id="navrow">
<img style="float: left;" src="questerslogoresized.png" />
<ul>
<li>Register</li>&nbsp&nbsp&nbsp
<li>About</li>&nbsp&nbsp&nbsp
<li>Reviews</li>&nbsp&nbsp&nbsp
<form id='login'  action='<?php echo $fgmembersite->GetSelfScript(); ?>' method='post'>
<div style="position: absolute; right: 120px;">
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='text' name='username' class="formlogin" placeholder='Username' id='username' value='<?php echo $fgmembersite->SafeDisplay('username') ?>' maxlength="20" />
<span id='login_username_errorloc' class='error'></span>
<input type='password' class="formlogin" placeholder="Password" name='password' id='password' maxlength="50" />
<span id='login_password_errorloc' class='error'></span>
</div>
<input type='submit' name='Submit' value='Submit' />
<!--<div class='short_explanation'><a href='reset-pwd-req.php'>Forgot Password?</a></div>-->
<div><span style='color: #fff; position: absolute; top: 55px; right: 398px;'><?php echo $fgmembersite->GetErrorMessage(); ?></span></div>
</div>
</form>
</ul>

<div id="passwordpopup" style="display: none;">
<div id="popup">
<h1>HI THERE!</h1>
</div>
</div>

这是我的CSS:

#popup {
 width: 175px;
 height: 100px;
 color: red;
 background: green;
 position: absolute;
 top: 15px; 
}

.formlogin {
 border-radius: 12px 12px 12px 12px;
 height: 24px;
 /*width: 200px;*/
 padding: 5px;
 border-style: solid;
 border-color: #0093cc;
 -webkit-transition: border-color 1s ease;
 -moz-transition: border-color 1s ease;
 -o-transition: border-color 1s ease;
 -ms-transition: border-color 1s ease;
 transition: border-color 1s ease;
 display: inline-block;
 font-size: 16px; 
 width: 12.5em;
 position: relative;
 top: -2em;
}

最后,这是我的PHP:

if(!$this->CheckLoginInDB($username,$password))
        {
            echo '<style type="text/css">
        #navrow {
            height: 70px;
        }
        </style>';
        $this->HandleError("Incorrect username or password.");
            return false;
        }

        $_SESSION[$this->GetLoginSessionVar()] = $username;

        return true;
    }

我想知道如何在我的PHP语句中passwordpopup所在的部分中显示(不隐藏)隐藏的div $this->HandleError("Incorrect username or password.");

希望你能提供帮助。再次感谢Stackoverflow!

2 个答案:

答案 0 :(得分:1)

只需使用!important覆盖内联样式:

#passwordpopup[style]{
display:block !important;
}

或者在你的PHP中:

echo '<style type="text/css">#navrow {height: 70px;} #passwordpopup[style]{display:block !important;}</style>';

答案 1 :(得分:0)

基本上你需要做一个关于用户是否在你决定隐藏div之前是否正确登录的测试。

<?php
   $viz = $this->CheckLoginInDB($username,$password) 
              ? ''
              : 'style="display: none;"' ;
?>
    <div id="passwordpopup" <?php echo $viz; ?>>
        <div id="popup">
            <h1>HI THERE!</h1>
        </div>
    </div>

或类似的东西。您的代码流程和$this的可用性在您的示例中并不明显。