Reputation: 2040
this is my form
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;
}
this is where I calculate the form values
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));
}
I am getting Unsupported operand types with this line
$form_state['dream_obj']->bmi = (($weight * 703) / ($tall * $height));
Upvotes: 0
Views: 2407
Reputation: 10155
The '#select' type does not support '#values'. The values are taken from the key in the options array.
eg.
$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"',
)
);
Upvotes: 1
Reputation: 25435
I suspect that 5'3" isn't the right form for an arithmetic operation. Try var_dumping it to see its actual form (I'm just guessing here, could it be an array?)
Convert it to an int or float value (es. using the metrical system. Why not translating the value in centimeters?) in order to use it as an operand.
Upvotes: 1