制作单选按钮

发布于 2024-07-30 18:26:02 字数 1305 浏览 2 评论 0原文

很抱歉这个问题,但是是否可以从这段代码中制作单选按钮而不是选择列表?

function _nodereview_form_review(&$form, $axis, $node) {
  static $options;
  if (!isset($options)) {
    $options = array(
    20 => -2,
    40 => -1,
    60 => 0,
    80 => 1,
    100 => 2,
    );
 }

$form['reviews'][$axis->aid] = array(
  '#type' => 'fieldset',
  '#title' => $axis->tag,
  '#collapsible' => TRUE,
  '#collapsed' => FALSE,
);

$form['reviews'][$axis->aid]['score'] = array(
  '#type' => 'select',
  '#title' => t('Score'),
  '#options' => $options,
  '#default_value' => $node->reviews[$axis->aid]['score'] ? $node->reviews[$axis->aid]['score'] : 50,
  '#description' => $axis->description,
  '#required' => TRUE,
);


if (NODEREVIEW_FIVESTAR_ENABLE) {
  $form['reviews'][$axis->aid]['score']['#type'] = 'fivestar';
  $form['reviews'][$axis->aid]['score']['#stars'] = variable_get('nodereview_fivestar_stars', 5);
}

$form['reviews'][$axis->aid]['review'] = array(
  '#type' => 'textarea',
  '#title' => t('Review'),
  '#default_value' => $node->reviews[$axis->aid]['review'],
  '#required' => TRUE,
);
}

我知道 '#type' => 'select' 应该是 '#type' => “广播”,但其他东西也应该改变。 我不知道到底是什么。

任何建议都非常感激地接受。

Sorry for this question, but is it possible to make radio buttons instead of select list from this piece of code?

function _nodereview_form_review(&$form, $axis, $node) {
  static $options;
  if (!isset($options)) {
    $options = array(
    20 => -2,
    40 => -1,
    60 => 0,
    80 => 1,
    100 => 2,
    );
 }

$form['reviews'][$axis->aid] = array(
  '#type' => 'fieldset',
  '#title' => $axis->tag,
  '#collapsible' => TRUE,
  '#collapsed' => FALSE,
);

$form['reviews'][$axis->aid]['score'] = array(
  '#type' => 'select',
  '#title' => t('Score'),
  '#options' => $options,
  '#default_value' => $node->reviews[$axis->aid]['score'] ? $node->reviews[$axis->aid]['score'] : 50,
  '#description' => $axis->description,
  '#required' => TRUE,
);


if (NODEREVIEW_FIVESTAR_ENABLE) {
  $form['reviews'][$axis->aid]['score']['#type'] = 'fivestar';
  $form['reviews'][$axis->aid]['score']['#stars'] = variable_get('nodereview_fivestar_stars', 5);
}

$form['reviews'][$axis->aid]['review'] = array(
  '#type' => 'textarea',
  '#title' => t('Review'),
  '#default_value' => $node->reviews[$axis->aid]['review'],
  '#required' => TRUE,
);
}

I know that '#type' => 'select' should be '#type' => 'radio', but something else also should be changed. I don't know what exactly.

Any suggestions are gratefully accepted.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魂ガ小子 2024-08-06 18:26:03

首先,#options 需要转换为每个单选按钮的值。 您可能还需要为每个按钮添加标签。

Well, for starters, the #options will need to be converted to the value for each radio button. You'll also probably need to add labels for each button as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文