While developing a form for Drupal 7, I need a few radio groups, placed inside a table (one radio group per table row). The radios are defined as '#type' => 'radio'
(not radios) and grouped together using the same name attribute per group. Nevertheless, when the form is submitted, the radio selections are not in the $form_state['values']
array, but in $form_state['input']
.
As you can see from the screenshots, all data is stored in input
, with the radios being outside the 'undefined'
array, even though I placed them in $form['undefined'][$key][x]
. In values
only the select and textfield data is retained.
Any ideas? It's been two days now that I'm trying to resolve this :( Thank you in advance.
function game_insert_form($form, &$form_state) {
dpm($form_state, 'form_state');
$test_data = array(
'2' => 'Alfa',
'4' => 'Beta',
'6' => 'Gamma',
'8' => 'Delta',
);
$header = array(
t('Name'),
array('data' => t('Existing'), 'colspan' => 2),
array('data' => t('New'), 'colspan' => 2),
);
$form['undefined'] = array(
'#tree' => TRUE,
'#theme' => 'table',
'#header' => $header,
'#rows' => array(),
);
foreach ($test_data as $key => $data) {
// Label
$label = array('#markup' => $data);
$children = array(&$label);
$row = array(array('data' => &$label));
unset($label);
// radio 0
$radio0 = array(
'#type' => 'radio',
'#return_value' => 0,
'#value' => 0,
'#name' => 'undefined-' . $key . '-radio',
);
$children['radio0'] = &$radio0;
$row[] = array('data' => &$radio0);
// dropdown
$select = array(
'#type' => 'select',
'#options' => array(0 => 'Zero', 1 => 'One'),
/*'#states' => array(
'enabled' => array(
':input[name="undefined-' . $key . '-radio"]' => array('value' => 0),
),
'required' => array(
':input[name="undefined-' . $key . '-radio"]' => array('value' => 0),
),
),*/
);
$children['select'] = &$select;
$row[] = array('data' => &$select);
// radio 1
$radio1 = array(
'#type' => 'radio',
'#return_value' => 1,
'#value' => 0,
'#name' => 'undefined-' . $key . '-radio',
);
$children['radio1'] = &$radio1;
$row[] = array('data' => &$radio1);
// textfield
$textfield = array(
'#type' => 'textfield',
'#maxlength' => 40,
'#size'=> 40,
);
$children['textfield'] = &$textfield;
$row[] = array('data' => &$textfield);
$form['undefined'][$key] = $children;
$form['undefined']['#rows'][] = $row;
unset($radio0);
unset($select);
unset($radio1);
unset($textfield);
}
$form['next'] = array(
'#type' => 'submit',
'#value' => t('Test'),
'#weight' => 0,
'#name' => 'test',
);
return $form;
}
function game_insert_form_submit($form, &$form_state) {
dpm($form_state, 'submit: form_state');
}
$form_state['input']
to get back the values but don't know if it is correct and where exactly it happens.