我对drupal 7很新。我需要将来自db表的名称添加到复选框中。我怎么做?我在下面写了回调函数函数:
function page_second_callback_form($form){
$result = db_query('SELECT n.names FROM {my_test_tab} n');
$output ='';
foreach($result as $item) {
$output .= $item->names;
}
$opt = array($output => $output,);
$form['check'] = array(
'#type' => 'fieldset',
'#title' => 'some',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['check']['chk_box'] = array(
'#type' => 'checkboxes',
'#title' => 'check box title go here.',
'#required' => TRUE,
'#descrfiption' => 'some descriptions for checkboxes.',
'#options' => $opt,
);
$form['check']['submit'] = array(
'#type' => 'submit',
'#value' => 'Delete',
);
return $form;
}
答案 0 :(得分:0)
您需要填充复选框的数据库选项数组,然后将此数组传递给复选框的#options
属性。
将您的代码更改为:
$output =array(); // the $output should be an array to store the database values.
foreach($result as $item) {
$output[] = $item->names; // fill the $output array with the database values.
}
然后:
$form['check']['chk_box'] = array(
'#type' => 'checkboxes',
'#title' => 'check box title go here.',
'#required' => TRUE,
'#descrfiption' => 'some descriptions for checkboxes.',
'#options' => $output, // the changed line.
);