How to hide field in node input form in drupal?

I use hook_node_presave to populate the taxonomy field with the group audience value. Thus, I am trying to hide the taxonomy field in the node data entry form. I tried hook_form_alter but for me this did not work. Is it possible to hide it?

+1
source share
1 answer
<?php

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'contenttype_node_form') {
    unset($form['somefield']);
  }
}
?>

It works just fine for me. Just change the form identifier and the key of the form field that you are aiming for, and the field should disappear.

Another option would be to hide it with CSS if the input was overridden in the presave anyway.

+5
source

All Articles