0

这是我的表格

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)); 
4

2 回答 2

1

我怀疑 5'3" 不是算术运算的正确形式。尝试 var_dumping 以查看其实际形式(我只是在这里猜测,它可能是一个数组吗?)

将其转换为 int 或 float 值(例如,使用公制。为什么不将值转换为厘米?)以便将其用作操作数。

于 2013-02-06T21:25:49.960 回答
1

“#select”类型不支持“#values”。这些值取自选项数组中的键。

例如。

$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"',
)
);
于 2013-02-07T09:06:48.973 回答