I'm trying to define a default value for my field using the php code option. I've entered the following value:

return array(0 => array('value' => '240'));

As suggested with 240 being the tid of the taxonomy term I would like to be the default value. This isn't working.

Comments

wim leers’s picture

Assigned: Unassigned » wim leers
Status: Active » Fixed
'#default_value' => array('240'),

This works.

This is an *extremely* basic Forms API question and therefore doesn't actually belong in any issue queue. Please use the forum next time, or do some proper searching. Then you'd have found this: http://api.drupal.org/api/5/file/developer/topics/forms_api_reference.html.

jmattturn’s picture

Status: Fixed » Postponed (maintainer needs more info)

I'm actually not using any API functions, I'm using the GUI interface for defining a cck field within a content type. I tried your suggestion and it still isn't working.

wim leers’s picture

Project: Hierarchical Select » Content Taxonomy
Version: 5.x-2.0-rc4 » 5.x-1.x-dev

Oh. Then this most definitely is a Content Taxonomy support question.

jeff h’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)

I believe this is an error in the help text - see http://drupal.org/node/173318#comment-704529

lazysoundsystem’s picture

I know this is an old thread for 5.x, but my 6.x problem is the same. I'm getting default values set for all the other cck fields, but for Content Taxonomy fields it seems like there's nothing I try that works. I noticed the Content Taxonomy form array already has a space for '#default_value' so I'm trying to fill that.

  foreach (element_children($form) as $child) {
// Set $default_value.

    if ($form[$child]['tids']) {
// This, for Content Taxonomy fields, isn't working:
      $form[$child]['tids']['#default_value'] = array('value' => $default_value);
      dsm($form[$child]['tids']['#default_value']);
    }
    else {
// This, for other fields, is working:
      $form[$child][0]['#default_value']['value'] = $default_value;
    }
  }