tableselect选中特定复选框

时间:2019-03-13 16:04:13

标签: php forms symfony drupal drupal-8

foreach ($courses as $user) {
              $options[$user['uid']] = array(
                'coursecode' => $user['coursecode'],
                'coursename' => $user['coursename'],
                'credithours' => $user['credithours'],
                'coursetype' => $user['coursetype'],
                'building' => $user['building'],
                'place' => $user['place'],
                'day' => $user['day'],
                'time' => $user['time'],

              );
            }
            $form['table'] = array(
              '#type' => 'tableselect',
              '#header' => $header,
              '#options' => $options,
              '#empty' => t('No Courses found'),
              '#js_select' => FALSE,
              '#attributes' => array('checked' => 'checked'),
            );

此代码生成了我可以注册的所有课程,是否有任何方法可以将默认值检查为默认值,我在选中特定复选框时遇到了问题

有什么帮助吗? 我正在使用drupal 8

1 个答案:

答案 0 :(得分:0)

//在您的foreach循环内

foreach($courses as $user) {
  $default_value[$user['uid']] = 1; // use 1 or 0 as appropriate

}

//现在选择表格

$form['table']['#default_value'] = $default_value;

// default_value并未随每个选项提供,而是在tableselect主数组中提供了一组默认值。

希望这可以解决您的问题。