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
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.
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".
An <input> element with a type="button" declaration and a valid value attribute does not need a label associated with it.
✎ 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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With