0

I've done a custom form that is a multiselect type form. When I edit the node, the options that were previously selected are not shown in the selected options part.

This is the code that I've done:

 foreach ($node->field_tem_tica[LANGUAGE_NONE] as $delta => $value) {
    $term2 = taxonomy_term_load($value['tid']);
 }

  $query2 = "SELECT name, tid FROM taxonomy_term_data WHERE vid=4 AND language = '$language_url';";
  $result = db_query($query2);
  foreach ($result as $row2) {
     $options3[$row2->tid] = t($row2->name);
  }

  $form['group_config']['tematicas'] = array(
     '#type' => 'multiselect',
     '#title' => t('Temáticas'),
     '#options' => $options3,
     '#required' => TRUE,
     '#multiple'=>TRUE,
     '#default_value'=> $term2,
     '#prefix' => '<p><br>',
     '#suffix' => '</p>',
     '#size'=>20,
  );

Does anybody see a mistake? Is there any way to see the default_values?

Thank you.

0

The default value needs to be the key of the options array, so assuming the rest of your code is correct, this should work:

$form['group_config']['tematicas'] = array(
  '#type' => 'multiselect',
  '#title' => t('Temáticas'),
  '#options' => $options3,
  '#required' => TRUE,
  '#multiple'=>TRUE,
  '#default_value'=> $term2->tid,
  '#prefix' => '<p><br>',
  '#suffix' => '</p>',
  '#size'=>20,
);

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.