0

我需要输出一个带有其他内容的 drupal 表单。这是我的代码:

$outputs="something else";
$outputs.=render(drupal_get_form(quotes_form));

function quotes_form(){
  $form = array();
      $form['arrival_city_1'] = array(
    '#default_value' => 'Finland',
    '#type' => 'select',
    '#required' => TRUE,
    '#options'=>array(
        'China' => 'China',
        'Finland' => 'Finland',
    ),
    '#weight'=>2,
    '#suffix'=>'</div>',
);
  return $form;
}

值“Filand”应该是默认值。但是,我检查了 html 输出:

<select id="edit-arrival-city-1" class="form-select required" name="arrival_city_1">
  <option value="China">China</option>
  <option selected="selected" value="Finland">Finland</option>
</select>

代码中选择的值是正确的,但“中国”显示在列表字段中。有谁知道为什么?谢谢

4

1 回答 1

0

下面的代码用于复选框情况。您可以轻松地为选择框创建。

$node_schema_type = array('micro_data','json_ld');
foreach($node_schema_type as $key => $value ){
  print $sch_type[$key] = $value;
}

 $form['schema_format'] = array(
    '#type' => 'checkboxes',
    '#options' => drupal_map_assoc(array('micro_data','json_ld')),
    '#default_value' => $sch_type,
    '#title' => t('Add schema type'),
  );

谢谢!

于 2016-02-23T08:48:19.627 回答