Removing HTML with PHP?

I thought I’d take a shot at this. I highly doubt it’s possible since PHP is a server-side language. But I’ve got a login form that submits through an AJAX call, and sends back errors to a div above the login form if the user submits bad password, etc. If the user logins in successfully, I display a control panel toolbar in the div above the form, however, the form remains.

Is there a way to remove that login form with PHP? Here’s the php code


if(mysql_num_rows($result_set) == 1) {
        
        $found_user = mysql_fetch_array($result_set);
        $_SESSION['user_id'] = $found_user['user_id'];
        $_SESSION['username'] = $found_user['username'];
        
        include('includes/admTools.php'); // here's where I include the toolbar
    }
    
    else {
    
        if($username == "" || $password == "") {
        
            $message = "<span class=\"message\">" . "<img src=\"/images/icon_warning.gif\" height=\"16\" width=\"16\" alt=\"Warning\" />" . "Please enter your username AND password</span>";
            echo $message;
            
        }
        
        else {
        
            if(!isset($found_user)) {
                
                $message = "<span class=\"message\">" . "<img src=\"/images/icon_warning.gif\" height=\"16\" width=\"16\" alt=\"Warning\" />" . "Username/password combination incorrect. Please make sure your caps lock key is off and try again.</span>";
            }
            
            
            echo $message;
        }
        
    }
    
    
    if(isset($_GET['logout']) && $_GET['logout'] == 1) {
                
        $message = "<span class=\"message\">You are now logged out</span>";
    }

display:none on the div with the form if session vars are set?

That’s not a bad idea. I’ll give it a try and let you know.

This won’t work either because I can’t just inject a style property into the page with php and expect the browser see it without reloading. :frowning:

Call a javascript function to set display to none then? You can certainly do that through conditional php.

Actually this did work, but it’s a little bit sloppy. I had to directly embed something like this


<style> #login { display: none; }</style>

It worked, I just hate embedding style tags in the middle of my HTML. Thanks!

ummm no you shouldn’t be doing it that way at all (and it was a horrible suggestion). all it does is hide it from public view not disable it, the form is still accessible. in your php/html you should have something like


<?php
if ( !($loggedin) ) 
{
?>
<form method="post" id="login">

</form>
<?php
}
?>

this is pseudo code, but the idea is that when you find that the user and password = true you should set a “logged” in session to true, based on whether that is true or not will determine if the form shows up or not, but you should be refreshing the page to login, this is one of those places ajax is not needed