jan199674
jan199674

Reputation: 753

Hide form with php on submit?

I have a simple php - password protecton / login based on a form which works. PHP-code is in page "secure.php" and includes the html-file "accessed.html" when user + pass is correct.

But i want the form to hide when hidden page (accessed.html) is shown. I have tried wrapping the form in a div and using javascript and display: none to hide, but it doesnt work - not locally or on server.

What am i doing wrong? It doesnt have to be js hiding the form after login..

PHP in top

    <?php
$user = $_POST['user'];
$pass = $_POST['pass'];

if($user == "a"
&& $pass == "a")
{
        include("accessed.html");
         echo "<script>
                    document.getElementById('wrap').style.display = 'none';
                </script>";
}

if(isset($_POST))
?>

And the form in the body:

    <div id="wrap">
    <form method="POST" action="secure.php">
        User <input type="text" name="user"></input>
        Pass <input type="text" name="pass"></input>
        <input type="submit" name="submit" value="access page"></input>
    </form>
</div>

Upvotes: 2

Views: 6210

Answers (2)

Lloyd Banks
Lloyd Banks

Reputation: 36648

I think this is what you are looking for my friend

<html>
<body>

<div id="wrap">
    <form method="POST" action="temp.php" target = "hidden">
       <input type="text" name="user">User</input>
       <input type="text" name="pass">Pass</input>
        <input type="submit" name="submit" value="access page" onclick = "closediv()"></input>
    </form>
</div>

<iframe name = "hidden" id = "hidden" style = "display: none"></iframe>

<script>

function closediv(){
    document.getElementById("wrap").style.display = "none";
    }

</script>

</body>
</html>

With the above code, you'll need to do your PHP processing on the current page. If this isn't doing what you want it to do and I misread your question, let me know and we can work on your predicament.

Upvotes: 0

Explosion Pills
Explosion Pills

Reputation: 191749

Move the <script> to after wherever you display "#wrap"

If you want to do it on the server side (PHP) just use an if statement.

Upvotes: 2

Related Questions