0

我对 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;
}
4

1 回答 1

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.
); 
于 2013-08-27T09:04:20.257 回答