How to hide a field on node data entry form in drupal?

自作多情 提交于 2019-12-23 01:18:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!