Search code examples
phpdrupalformsdrupal-6

How to hide a field in a Drupal form


I have a specific content type in drupal6. I want to implement a hook, which hides the body field of that content type from the add form, but not from the edit form. How can I do that?


Solution

  • You can use hook_form_alter. Which you can programmatically alter the contents of the form api build. This gives you the full $form array of which you can simply unset($form['the_field_you_dont_want']);.

    But the easier way to get rid of the body field is in the edit content type there is a field labelled 'Body field label:' just leave this blank and the body field will be omitted.