forms - 以 Drupal 形式设置单个单选按钮的样式

标签 forms drupal elements styling

我有这组单选按钮,其中每个按钮都通过样式属性设置了自己的位置。我想如何使用 drupal form api 归档相同的文件。我找到了如何整体设计风格,而不是作为小组内的个人控制。这是我的 html 代码的样子 -

<input type="radio" name="base_location" checked="checked" value="0" style="margin-left:70px;float:left;"/><span style="float:left;">District</span>
  <input type="radio" name="base_location" value="1" style="margin-left:50px;float:left;"/><span style="float:left;">MRT</span>
  <input type="radio" name="base_location" value="2" style="margin-left:60px;float:left;"/><span style="float:left;">Address</span>

这是我被困在的 Drupal 代码 -
$form['base_location'] = array(
   '#type' => 'radios',
   '#title' => t('base location'),
   '#default_value' => variable_get('search_type', 0),
   '#options' => array(
'0'=>t('District'),
'1'=>t('MRT'),
'2'=>t('Address')),
   '#description' => t('base location'),

我知道#type=>radio 的存在。但是,在这方面,我不知道如何将所有单选按钮组合在一起。如果我对它们都使用相同的数组键,它们会相互碰撞。如果我不这样做,他们就不会被视为同一组的一部分。我提前谢谢你。

最佳答案

如果您使用 Drupal 6.x Form API 和 #type=>radios ( http://api.drupal.org/api/function/theme_radios/6 ) 每个单选元素都有其唯一的 ID,您可以使用它来应用适当的 CSS。

你提供的例子

$form['base_location'] = array(
  '#type' => 'radios',
  '#title' => t('base location'),
  '#default_value' => variable_get('search_type', 0),
  '#options' => array(
  '0'=>t('District'),
  '1'=>t('MRT'),
  '2'=>t('Address')),
  '#description' => t('base location'),
);

应该像这样输出标记:
<div id="base-location-0-wrapper" class="form-item">
  <label for="base-location-0" class="option"><input type="radio" class="form-radio" value="0" name="base_location" id="base-location-0"> District</label>
</div>
<div id="base-location-1-wrapper" class="form-item">
  <label for="base-location-1" class="option"><input type="radio" class="form-radio" value="1" name="base_location" id="base-location-1"> MRT</label>
</div>
<div id="base-location-2-wrapper" class="form-item">
  <label for="base-location-2" class="option"><input type="radio" class="form-radio" value="2" name="base_location" id="base-location-2"> Address</label>
</div>

应用以下 CSS,你应该被设置。
  #base-location-0-wrapper,
  #base-location-1-wrapper,
  #base-location-2-wrapper {
    display:inline;
    margin-left:50px;
  }

关于forms - 以 Drupal 形式设置单个单选按钮的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2854287/

相关文章:

forms - CodeIgniter:具有多个输入的表单的 Controller 结构

mysql - 恢复 Drupal 服务器上 MySQL 的 root 访问权限

html - 如何根据屏幕大小缩放 HTML 中元素的大小?

html - 脚本输出结束 - CGI/HTML

html - 移动联系表

php - 地理编码器不适用于 "Geocode from another field"

drupal - 为什么我的 drupal 7 子菜单没有显示?

c - 如何使用 C 选择数组中的多个元素?

java - Selenium - 如何捕获页面上的所有网页元素和关联定位器?

c# - 函数不会返回任何内容