【问题标题】:drupal 7 select field selected value does not work in render formdrupal 7选择字段选择值在渲染表单中不起作用
【发布时间】:2014-01-22 21:25:12
【问题描述】:

我需要输出一个带有其他内容的 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>

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

【问题讨论】:

  • 你是什么意思,你不想在你的 html 选择列表中选择 'china' 选项??
  • @prabeen 我希望列表显示芬兰而不是中国。但它们都在选择列表中。

标签: input drupal-7 drupal-render


【解决方案1】:

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

$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'),
  );

谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-15
    • 1970-01-01
    • 1970-01-01
    • 2013-05-04
    • 2020-06-25
    • 2019-03-17
    相关资源
    最近更新 更多