如何在drupal中构建一个列出用户角色的表单?

时间:2011-12-01 12:01:06

标签: php drupal drupal-7

我想显示一个表单,其中包含针对每个用户角色的复选框 我有这个

$roles = user_roles($membersonly = FALSE, $permission = NULL);

$form['trc_user_roles'] = array(
        '#type'         =>  'chekboxes',
        '#title'        =>  'Allow users who can see uploaded files',
        '#options'      =>  $roles,
        '#descripion'   =>  'User roles checked are able to see site-wide uploads.'
    );

return system_settings_form($form);

输出是空白页。

1 个答案:

答案 0 :(得分:2)

您在调用user_roles()和拼写错误('chekboxes')时出现语法错误。试试这个:

$roles = user_roles(FALSE, NULL);

$form['trc_user_roles'] = array(
  '#type'         =>  'checkboxes',
  '#title'        =>  'Allow users who can see uploaded files',
  '#options'      =>  $roles,
  '#descripion'   =>  'User roles checked are able to see site-wide uploads.',
  '#default_value' => variable_get('trc_user_roles', array())
);

return system_settings_form($form);

我还添加了#default_value属性,因此下次重新加载表单时,系统会预先填写选定的选项。