5

I have this code in cake php but it generates a bunch of labels along with the input that I do not like. How can I get rid of them? I just want the input.

echo $this->Form->hidden('user_role', array('value'=> '2'));
echo $this->Form->input('user_username');
echo $this->Form->input('user_password', array('type' => 'password'));
echo $this->Form->input('user_fname');
echo $this->Form->input('user_lname');
echo $this->Form->input('user_email');
echo $this->Form->input('user_phone');
echo $this->Form->input('user_cellphone');
echo $this->Form->input('user_address1');
echo $this->Form->input('user_address2');
echo $this->Form->input('user_city');
echo $this->Form->input('user_zip');
echo $this->Form->end('Submit');

Thank you

1

1 Answer 1

19

Labels are good for usability. But you can remove them in each form field adding the following:

$this->Form->input('user_username', array( 'label' => false ));

You can also disable labels by default when creating the form:

$this->Form->create('User', array('inputDefaults' => array('label' => false)));

Futher information available at their site:

4
  • One small question... the reason why i am not using that label.. is because it does not allow me to position it.. right now the label and the inputs look weird, unorganized if one label is longer than the others
    – user710502
    Dec 10, 2011 at 2:59
  • @user Sounds more like a CSS layout problem than a problem with labels as such.
    – deceze
    Dec 10, 2011 at 3:19
  • You must use css to make your form "well positioned". Take a look at this post: dailycoding.com/Posts/…
    – felipecrp
    Dec 10, 2011 at 3:21
  • you can use $this->Form->control('user_username'); which will show only input field, no label.
    – naf4me
    Nov 21, 2017 at 6:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.