drupal形式的不支持的操作数类型

时间:2013-02-06 21:21:59

标签: php drupal

这是我的表格

function dreamcharts_step7_form(&$form, &$form_state) {
   $dream = &$form_state['dream_obj'];
   $form['weight'] = array(
    '#type' => 'textfield',
    '#title' => 'Weight',
   );




    $form['tall'] = array(

    '#title' => 'How tall are you?',
    '#type' => 'select',
    '#required' => 1,
    '#default_value' => $dream->tall,
    '#value' => array( 
      '0' => '58',
      '1' => '59',
      '2' => '60',
      '3' => '61',
      '4' => '62',
      '5' => '63',
      '6' => '64',
      '7' => '65',
      '8' => '66',
      '9' => '67',
      '10' => '68',
      '11' => '69',
      '12' => '70',
      '13' => '71',
      '14' => '72',
      '15' => '73',
      '16' => '74',
      '17' => '75',
      '18' => '76',

    ),
    '#options' => array(
      '0' => '4\' 10"',
      '1' => '4\' 11"',
      '2' => '5\' 0"',
      '3' => '5\' 1"',
      '4' => '5\' 2"',
      '5' => '5\' 3"',
      '6' => '5\' 4"',
      '7' => '5\' 5"',
      '8' => '5\' 6"',
      '9' => '5\' 7"',
      '10' => '5\' 8"',
      '11' => '5\' 9"',
      '12' => '5\' 10"',
      '13' => '5\' 11"',
      '14' => '6\' 0"',
      '15' => '6\' 1"',
      '16' => '6\' 2"',
      '17' => '6\' 3"',
      '18' => '6\' 4"',
    )
  );

   $form['tip'] = array(
    '#type' => 'markup',
    '#prefix' => '<div id="hint">',
    '#suffix' => '</div>',
    '#value' => 'The combination of your weight and height lets us know your Body Mass Index or BMI.',
   );   

  $form_state['no buttons'] = TRUE; 
}

这是我计算表格值的地方

function dreamcharts_step7_form_submit(&$form, &$form_state) {


  $tall = $form_state['values']['tall'];
  $weight =  $form_state['values']['weight'];

  $form_state['dream_obj']->bmi = (($weight * 703) / ($tall * $height)); 

}

我使用此行

获得不支持的操作数类型
  $form_state['dream_obj']->bmi = (($weight * 703) / ($tall * $height)); 

1 个答案:

答案 0 :(得分:1)

'#select'类型不支持'#values'。这些值取自options数组中的键。

例如

$form['tall'] = array(

'#title' => 'How tall are you?',
'#type' => 'select',
'#required' => 1,
'#default_value' => $dream->tall,
'#options' => array(
  '58' => '4\' 10"',
  '59' => '4\' 11"',
  '60' => '5\' 0"',
  '61' => '5\' 1"',
  '62' => '5\' 2"',
  '63' => '5\' 3"',
  '64' => '5\' 4"',
  '65' => '5\' 5"',
  '66' => '5\' 6"',
  '67' => '5\' 7"',
  '68' => '5\' 8"',
  '69' => '5\' 9"',
  '70' => '5\' 10"',
  '71' => '5\' 11"',
  '72' => '6\' 0"',
  '73' => '6\' 1"',
  '74' => '6\' 2"',
  '75' => '6\' 3"',
  '76' => '6\' 4"',
)
);