以drupal形式设计单个单选按钮

And*_*rew 5 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>
Run Code Online (Sandbox Code Playgroud)

这是我坚持的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'),
Run Code Online (Sandbox Code Playgroud)

我知道#type =>无线电存在.但是,我不知道如何在这方面将所有单选按钮组合在一起.如果我对所有这些使用相同的数组键,它们将相互冲突.如果我不这样做,他们就不会被视为同一群体的一部分.我提前谢谢你.

Eri*_*ärd 3

如果您使用 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'),
);
Run Code Online (Sandbox Code Playgroud)

应该像这样输出标记:

<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>
Run Code Online (Sandbox Code Playgroud)

应用以下 CSS,您就应该设置好了。

  #base-location-0-wrapper,
  #base-location-1-wrapper,
  #base-location-2-wrapper {
    display:inline;
    margin-left:50px;
  }
Run Code Online (Sandbox Code Playgroud)