Default values for Content Taxonomy fields in Drupal

Posted by lazysoundsystem on Stack Overflow See other posts from Stack Overflow or by lazysoundsystem
Published on 2010-05-11T18:10:12Z Indexed on 2010/05/11 18:14 UTC
Read the original article Hit count: 212

Filed under:

I'm trying to set the default value for a Content Taxonomy field in a hook_form_alter, but can't pin down the necessary format. I've tried this and many variations:

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;
  }
}

Can anyone tell me what I'm missing?

© Stack Overflow or respective owner

Related posts about drupal