tags:

views:

182

answers:

2

Hi,

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

A: 

Try this out.

<p>Username</p>    
<?php echo $form->input('username', array('div' => false, 'label' => false)) ?>
Flash84x
One of the nice things about `<label>` tags is clicking their text places the cursor focus in the corresponding `<input>` (or checks a checkbox or radio control). Replacing the `<label>` with a paragraph tag sacrifices this functionality. Moreover, removing the `<div>` wrapper prevents Cake from rendering its "automagic" form validation errors. Your solution sacrifices too much to gain a simple line-break.
Daniel Wright
+2  A: 

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.

Daniel Wright