Hi,

Regarding CCK, I have a question if anyone would be so kind to answer:

How do I hide fields created with CCK? I do not want to them show up when creating a new type because they will automatically be filled in during db insertion or filled in at a later date.

for example fields such as:
date_created
num_products_imported

cheers,
Frychiko

Comments

jefflane’s picture

I thought it was the following, but this is not true, the following is just for the form display, not for someone creating content

Select the following
Administer -> Content Management -> Content Types -> Manage Fields -> Display Fields

Then for each element you want to be hidden, select "hidden" from the drop down menu in each of the following
Label
Teaser
Full Node

Then hit save, that should do it.

WorldFallz’s picture

For content creation, you could either use a computed field or use the content permissions module and don't give the view field permission to whatever roles you don't want to see it.

nerdoc’s picture

think the latter doesn't work.
if you give no view/edit rights to roles to view some fields, theese fields are NOT automatcally filled out to their standard values if you don't have the right permissions...

satish04mca’s picture

I tried this
//----------------------------------
Select the following
Administer -> Content Management -> Content Types -> Manage Fields -> Display Fields

Then for each element you want to be hidden, select "hidden" from the drop down menu in each of the following
Label
Teaser
Full Node
//------------------------------------

But its not working..
I have to put some default javascript code into hidden field for displaying sponsered link in between of the page.
How???

TIA

gala4th’s picture

Following code is able to make a CCK field becoming a hidden type field.

Method 1:

/**
* Implementation of hook_form_alter().
*/
function YourModuleName_form_alter(&$form, $form_state, $form_id) {
  if (isset($form['type']) && isset($form['#node'])) {
    ### Make a CCK field becoming a hidden type field.
    // ### Use this check to match node edit form for a particular content type.
    if ($form_id === 'YourContentTypeName_node_form') {
      $form['CCK_Field_Name']['#prefix'] = '<div style="display:none;">';
      $form['CCK_Field_Name']['#suffix'] = '</div>';
    }
  }
}

Method 2:

/**
* Implementation of hook_form_alter().
*/
function YourModuleName_form_alter(&$form, $form_state, $form_id) {
  if (isset($form['type']) && isset($form['#node'])) {
    ### Make a CCK field becoming a hidden type field.
    // ### Use this check to match node edit form for a particular content type.
    if ($form_id === 'YourContentTypeName_node_form') {
      $form['#after_build'] = array('_test_set_cck_field_to_hidden');
    }
  }
}

/**
 * 
 * @param
 * @return
*/
function _test_set_cck_field_to_hidden($form, &$form_state) {
  $form['field_NameToBeHidden'][0]['value']['#type'] = 'hidden';
  $form['field_NameToBeHidden'][0]['#value']['value'] = 'testValue';

  return $form;
}
truyenle’s picture

Thank a lot gala4th, method 1 work for me like charm.

Truyenle

wkmit’s picture

One thing to bear in mind with method 1 is that someone can simple use firebug to set display:block to make the element visible.
Not a problem if you are not worried about security however.

nobarte’s picture

Method 2 is more secure than 1.
User can not manipulate the variable.

ezarria’s picture

Method 1 Ok... Thanks!!!

leisurman’s picture

Hello, I would like to hide 2 cck fields.
File attachments (upload)
Upload Inline File (field_upload_inline_file)

What do I put in place of 'YourModuleName'?

YourModuleName_form_alter

Hugo Estrada’s picture

Anyone knows if they are going to include it? There should be a difference from excluding the field and turning it into a hidden field.

AviadG’s picture

If you have your field populated automatically with a default value (you set up when creating the field), then you can hide the field on the form and expose it on the node's view easily. All you have to do is to set the permissions... do not give the role permission to edit the field on the form, and do give the same role the permission to view the field. So, without the user doing anything, after creating the node, the new field will come up.