Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid labels of inputs

Tags:

cakephp

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

like image 833
user710502 Avatar asked Dec 10 '11 02:12

user710502


People also ask

How do I hide input field labels?

The best way to hide the label in form input field, is to pass empty value to array on 'attributeLabels()' function in the model. public function attributeLabels() { return [ 'id' => 'ID', 'gender' => 'Gender', 'client_name' => '', . . . ] } That doesn't remove the label. Just hides doesn't display a text.

Should all inputs have labels?

Answer. It is best to ensure that all form inputs have a visible label. Visible labels help users understand the input's purpose. Placeholder text does not suffice and should not be considered as "good enough".

Is label necessary for input HTML?

An <input> element with a type="button" declaration and a valid value attribute does not need a label associated with it.

What are input labels?

✎ Technique: Input labelsDescriptive labels help users understand the purpose of a form control. Labels should be associated with their controls so that when the input is focused, the label is announced by screen readers.


1 Answers

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:

  • http://book.cakephp.org/view/1398/options-label
  • http://book.cakephp.org/view/1616/x1-3-improvements
like image 57
felipecrp Avatar answered Sep 27 '22 19:09

felipecrp