开发者

CakePHP - Have the label and form in Form helper on different line

开发者 https://www.devze.com 2022-12-27 07:07 出处:网络
I\'m using this code now echo $form->input(\'username\'); How do 开发者_高级运维I make sure the label shows up on a different line than the input field?

I'm using this code now

echo $form->input('username');

How do 开发者_高级运维I make sure the label shows up on a different line than the input field?

I managed to imitate what I'm trying to do, just want to make sure that I'm using it the right way.

echo $form->label('username', 'Username');

echo $form->input('username', array('label' => false));

Thanks,

Tee


The core of your request is putting a line-break between the <label> and <input> tags created by the FormHelper::input method. You can accomplish this in several ways. Probably the simplest option is the following:

echo $form->input('User.username', array('between'=>'<br />'));

Or you could also use a pure CSS solution, something like:

<style type="text/css">
    div.input label { display: block; }
</style>
<?php echo $form->input('User.username'); ?>

This second option would leave you with cleaner PHP in your views, at the cost of more potential layout/stylesheet headaches.


Try this out.

<p>Username</p>    
<?php echo $form->input('username', array('div' => false, 'label' => false)) ?>
0

精彩评论

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