I have created a content type which consists of a title a .zip file and a screenshot using Drupal 7's site builder.

When a user adds an instance of this content type I would like for them to only have exposed fields for the .zip file and the title. I have a custom module that unzips the .zip file and does some analysis and I would like to extract the screenshot at this time.

Is there anyway that I can have the new content form of my content type not show the screenshot field?


Three good options:

  • Display Suite has a feature to hide fields from the form
  • You can use hook_form_node_form_alter to remove the field

Edit: per Clive's suggestion, set ['#access'] = FALSE instead of unset($form['field_zip_file'])

Create a new module, (create MY_MODULE.info, MY_MODULE.module), and add this to MY_MODULE.module:


  function MY_MODULE_form_node_form_alter (&$form, &$form_state, $form_id) {
    if ($form['#node']->type == 'my_content_type') {
      if ($form['nid']['#value'] == '') {
        $form['field_zip_file']['#access'] = FALSE;
  • Use CSS to make it disappear:

Add this to your theme's CSS file:

body.page-node-add #edit-field-zip-file {
  display: none;
| improve this answer | |
  • Sweet I tried your second suggestion and it worked like a charm! Thanks! – Mike2012 Apr 25 '12 at 17:44
  • 3
    Removing the element from the form array isn't the best idea (it may well cause PHP warnings in validate/submit handlers). The best way would be to use $form['field_zip_file']['#access'] = FALSE;. – Clive Apr 25 '12 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.