1

I need to output one drupal form with other content. Here is my code:

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

The value "Filand" should be the default value. However, i check the html output:

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

The selected value is correct in the code, but "China" is shown in the list filed. Anyone know why? thanks

user3210341
  • 77
  • 1
  • 2
  • 14

2 Answers2

0

Below code use in checkbox cases.You can create easily for selectboxes.

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

Thanks!

Sourabh Bhutani
  • 623
  • 11
  • 21
0

I'm not sure why yet, but the render function calls form_select_options, which seems to ignore #default_value, but does use #value to set the selected option. Normally #value is more of a permanent setting, rather than an initial setting.

jgreep
  • 2,111
  • 4
  • 23
  • 31