如何将“radios”添加到围绕 theme_table 构建的表单中?
使用单个“复选框”或单个“ radio ”似乎工作正常,但是一旦我使用“ radio ”,就根本没有单选按钮呈现。
从另一个 Stack Overflow 问题中,我看到了 form_process_radios()
提到,并使用它实际上显示了单选按钮。但是它们不再捆绑在一起,并且可以立即将它们全部置于“开启”状态。
有任何想法吗?
最佳答案
简单的回答:你不能轻易。 (尽管您可能会成功定义自己的处理器,使用 expand_radios,核心的东西!)。
更长的答案:radios
用途 theme_radios .正如您所看到的,它使用单个 DIV 包装器,这使得无法在 table 上展开 radio 。
您最好做的是创建一个分层表单,其中一个 radio
每个选项。避免 radios
.通过对它们进行分层分组 name
将是相同的,这就是方式radios are grouped .
# from install.php:
foreach ($names as $profile => $name) {
$form['profile'][$name] = array(
'#type' => 'radio',
'#value' => 'default',
'#return_value' => $profile,
'#title' => $name,
'#description' => isset($profiles[$profile]['description']) ? $profiles[$profile]['description'] : '',
'#parents' => array('profile'),
);
}
然后,在围绕表单构建表格的主题功能中,在适当的表格单元格中呈现每个 radio 。
关于forms - 带 radio 的 Drupal 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5414330/