In D7, I am trying to "hide" a field label through form_alter:
case 'postal_code_node_form':
// Set fields as not required
$form['title']['#required'] = FALSE;
$form['body']['#required'] = FALSE;
// Add css to hide fields.
$form['body']['#attributes'] = array('style' => 'display:none');
$form['title']['#attributes'] = array('style' => 'display:none;');
$form['body']['#label_display'] = 'hidden';
$form['title']['#label_display'] = 'hidden';
break;
Unfortunately, the label is still displayed. I could do it through CSS or JavaScript, but I would prefer doing this through hook_form_alter()
, so all form modifications are at the same place.