I use a tableselect to output a list of terms and per row I want a drop down (select):
$header = array(
'name' => array('data' => t('Name')),
'weight' => array('data' => t('Weight')),
);
$options = array();
foreach ($terms as $term) {
$options[$term->tid] = array(
'name' => array(
'data' => array(
'#title' => $term->name,
'#type' => 'link',
'#href' => sprintf('/taxonomy/term/%d', $term->tid),
),
),
'weight' => array(
'data' => array(
'#type' => 'select',
'#options' => range(1,25),
),
),
);
}
$form['term_list']['list'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
);
My problem is that I do not see the value of the drop down (select) when I debug.
function example_block_save($delta = '', $edit = array()) {
debug($edit, null, true);
}
Here is what I get:
[term_list] => Array
(
[list] => Array
(
[5] => 5
[4] => 0
[6] => 0
)
)
When I check the code I can see that the select has no name, I'm guessing that's why I don't see it in the debug.
#tableselect
form element type. Instead, it's used to select from a list, with#options
representing a key=>value set of selections (like aselect
element, where the keys represnet the data value that is passed when your form is submitted). To embed form elements, you probably need to render them seperately by doing something like$element = theme_form_element($element);
. That means you'll need to do your own special processing of $_POST, though. see bit.ly/PzilAr and bit.ly/L3qpD9 – cam8001 Jul 9 '12 at 10:24