开发者

Applying CSS to a form

开发者 https://www.devze.com 2022-12-22 03:46 出处:网络
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?

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>';


}


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 ;)


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.


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号