问题
I'm using hook_node_presave to pre-populate taxonomy field with group's audience value. Thus, I'm trying to hide taxonomy field on a node data entry form. I tried hook_form_alter, but it didn't work for me. Is it possible to hide it?
回答1:
<?php
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'contenttype_node_form') {
unset($form['somefield']);
}
}
?>
This works for me just fine. Just change the form id and key of the form field you are targeting, and the field should go away.
Another option would be hiding it with CSS if the input was overridden in presave anyway.
来源:https://stackoverflow.com/questions/6831024/how-to-hide-a-field-on-node-data-entry-form-in-drupal