1

I can't get CSS to apply to the function below. Is it because it's a form or because it uses dl, dt, and dd tags?

Thanks in advance,

John

function show_loginform($disabled = false)
{

    echo '<form name="login-form" id="login-form" method="post" action="./index.php"> 

  <div class=\"logintitle\">Please login</div> 
  <dl class=\"usernamefield\"> 
    <dt class=\"siteadd\"><label title="Username">Username: </label></dt> 
    <dd class=\"siteadd\"><input tabindex="1" accesskey="u" name="username" type="text" maxlength="30" id="username" /></dd> 
  </dl> 
  <dl class=\"siteadd\"> 
    <dt class=\"siteadd\"><label title="Password">Password: </label></dt> 
    <dd class=\"siteadd\"><input tabindex="2" accesskey="p" name="password" type="password" maxlength="15" id="password" /></dd> 
  </dl> 
  <ul> 
    <li><a href="http://www...com/sandbox/register.php" title="Register">Register</a></li> 
    <li><a href="http://www...com/sandbox/lostpassword.php" title="Lost Password">Lost password?</a></li> 
  </ul> 
  <p class=\"siteadd\"><input tabindex="3" accesskey="l" type="submit" name="cmdlogin" value="Login" ';
    if ($disabled == true)
    {
        echo 'disabled="disabled"';
    }
    echo ' /></p></form>';


}
9
  • 1
    you should check your generated html using firebug, and see from there. Let us know :-) Commented Mar 5, 2010 at 3:13
  • 1
    Not completely related to the issue, As I am pretty much alien to PHP, but is this way PHP guys code their HTML? PHP code spits complete HTML? Not HTML code has php scriptlets? Commented Mar 5, 2010 at 3:15
  • 2
    @Teja The above is quite wrong on many levels... :) Commented Mar 5, 2010 at 3:17
  • @deceze Why is it wrong? Commented Mar 5, 2010 at 3:23
  • This is why PHP gets a bad rap... :( Commented Mar 5, 2010 at 3:27

3 Answers 3

4

You have an escaping error within your code. To show just an extract:

  echo ' ... <div class=\"logintitle\">Please login</div>  ... ';

You use ' but then escape ", which will lead to \" being printed out to the user. You don't have to escape " when using ' as main quotes. This could be the problem for your browser, not correctly identifying your divs and thereby not applying css.

addendum:

when echo'ing large portions (as already mentioned it would be better to use a templating system, e.g. smarty), you can close and reopen your php tags for better reading:

function show_loginform($disabled = false)
{

?>
<form name="login-form" id="login-form" method="post" action="./index.php"> 

  <div class="logintitle">Please login</div> 
  <dl class="usernamefield"> 
    ...
<?php
   if(true)
   {
      echo 'foobar';
   }
?>

   ...
  </p></form>
<?php

} // function end

and you can crash most syntax highlighters doing this btw ;)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks... this was the problem.
0

Aside from mixing HTML and PHP in that way, your code is valid enough. I am able to apply CSS to the above exact code. The problem is in your CSS.

Comments

0

This doesn't solve your problem but a tip for future programming:

It's not necessary to compare $disabled to true as $disabled is already a boolean.


if ($disabled == true){
    echo 'disabled="disabled"';
}

The following shows much more of an understanding of boolean types:


if ($disabled){
    echo 'disabled="disabled"';
}

Post your CSS and it will be much easier to help you with your original problem...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.