Drupal Html 数组。如何在字段集中引用不断变化的单选选择

发布于 2024-12-17 04:41:10 字数 1385 浏览 0 评论 0原文

我无法使这个 Drupal html 数组在更改单选选项时触发可见属性。我已将所有内容移至字段集内,不确定这是否有任何区别。

有谁知道为什么不火吗?

function services_formation_founders($form, &$form_state) {
$form = array();
$form['#tree'] = TRUE;

$form['description'] = array(
'#type' => 'item',
'#title' => t('Founders form'),
);

$form['founder']['add_officer'] = array(
'#type' => 'fieldset',
'#title' => t('Add Founder'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#states' => array(
  'visible' => array(TRUE,
  ),
),
);

$form['founder']['add_officer']['founder_type'] = array(
'#type' => 'radios',
'#options' => array(
  'individual'   => t('Individual'),
  'corporate' => t('Corporation'),
 ),
  '#default_value'=>'individual',
'#title' => t('What type of Founder?')
);

if (empty($form_state['num_names'])) {
$form_state['num_names'] = 1;
}

  $form['founder']['add_officer']['individual'] = array(
'#type' => 'textfield',
'#title' => t('Individual'),
'#states' => array(
  'visible' => array(
    ':input[name="founder_type"' => array('value' => "individual"),
  ),
),
);

$form['founder']['add_officer']['corporation'] = array(
'#type' => 'textfield',
'#title' => t('Corporation'),
'#states' => array(
  'visible' => array(
   ':input[name="founder_type"' => array('value' => "corporate"),
  ),
 ),
);
return $form;
}

I cannot make this Drupal html array fire the visible property on change of radio option. I have moved everything inside of the fieldset, not sure if this makes any difference.

Does anyone know why it isn't firing?

function services_formation_founders($form, &$form_state) {
$form = array();
$form['#tree'] = TRUE;

$form['description'] = array(
'#type' => 'item',
'#title' => t('Founders form'),
);

$form['founder']['add_officer'] = array(
'#type' => 'fieldset',
'#title' => t('Add Founder'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#states' => array(
  'visible' => array(TRUE,
  ),
),
);

$form['founder']['add_officer']['founder_type'] = array(
'#type' => 'radios',
'#options' => array(
  'individual'   => t('Individual'),
  'corporate' => t('Corporation'),
 ),
  '#default_value'=>'individual',
'#title' => t('What type of Founder?')
);

if (empty($form_state['num_names'])) {
$form_state['num_names'] = 1;
}

  $form['founder']['add_officer']['individual'] = array(
'#type' => 'textfield',
'#title' => t('Individual'),
'#states' => array(
  'visible' => array(
    ':input[name="founder_type"' => array('value' => "individual"),
  ),
),
);

$form['founder']['add_officer']['corporation'] = array(
'#type' => 'textfield',
'#title' => t('Corporation'),
'#states' => array(
  'visible' => array(
   ':input[name="founder_type"' => array('value' => "corporate"),
  ),
 ),
);
return $form;
}

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

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

发布评论

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

评论(1

瑾夏年华 2024-12-24 04:41:10

将 $ 符号放在第 2 行

$form = array();

Place $ sign at line no 2

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