开发者

how to set css for Zend form?

I m New to Zend framework and I have created a login form in PHP and I 开发者_开发知识库want to set Its css style but I don't know how to set it.

Please Suggest some code or link.....

Thanks in Advance


When you are creating your form elements you have to give them names:

$form->addElement('text', 'username');
$form->addElement('password', 'password');
$form->addElement('submit', 'submit');

These become the ids of the elements. You can target these elements using CSS selectors just like any other element:

input#username,
input#password
{
    width:200px
}
input#username
{
    background-color:yellow;
}

You can also give the form a name.

Another method is to give your form elements classes:

$element->setAttrib('class', 'username');

As you become more experienced with ZF you may want to start looking at form element decorators. These allow you to show error messages, labels, and extra divs or whatever around your form elements.


I would recommend against being too specific with styling in your forms. You'll notice that most of the built-in decorators are fairly basic markup. Once you start mixing in css classes your forms become too view-layer heavy and it makes them difficult to reuse. For example in a mobile vs. full browser context.

Instead, echo your form inside of a div and use css to style child elements.

<div class="login-form">
    <?php echo $form ?>
</div>

div.login-form input[type=text] { width: 200px; }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜