Hide Node Fields In Drupal 6, Best Practice

Drupal natively includes a lot of fields on the add/edit form that seem superfluous to everyday use, and which complicates the user experience. One well-known example is the "show summary in full view" checkbox. If you're like me and think that it's important to make the user interface as simple and intuitive as possible, you will need a way to remove all these fields that the end user doesn't really need. The most common approaches to this problem are to manipulate php or css.

Hiding these fields with css is easy enough, but this is not a good solution as the fields are still rendered which makes it both a bloater and a security risk if you want to hide the fields for reasons related to access control. The preferred method is instead to use php to make sure they are never rendered to html. The first step is to find out what the name of the field is. You can do this by first checking out the highest relevant element in the hierarchy through Firebug or similar tool to get a clue to what the string might be (look at classes and id for example), and then creating a form_alter function and display the $form variable with for example a looping drupal_set_message, or dpm if you've installed the Devel module. The field name is usually a first level array key in $form, but for example in the case of the "show summary in full view" field it is located at $form['body_field']['teaser_include']. 

The next step is to hide the field. From what I've seen, the most common suggestion is to use unset() for this. However, this method can produce bugs as the field is then actually removed from the form. Rather, what you want to do is to disable the access by setting {field location}['#access'] = false; where {field location} is for example $form['body_field']['teaser_include'].

Of course, this method hides the field for ALL users, including the administrator account. What I do is to create a custom permission for each field with hook_perm(), and then check user_access() against that field to decide whether it should be displayed or not. That gives me complete control over which fields should be visible to which roles.