我有4个单选按钮,我想给每个按钮添加一个描述。而不仅仅是单选按钮组。
这是我的代码:
$form['bedrijfsfiche'] = array(
'#type' => 'radios',
'#title' => t('Keuze bedrijfsfiche'),
'#options' => array('basis' => t('Basisbedrijfsfiche: €125'), 'Uitgebreid' => t('Uitgebreide bedrijfsfiche: €250'), 'gratis' => t('Gratis bedrijfsfiche'), 'contact' => t('Contacteer mij telefonisch voor meer uitleg')),
'#access' => $admin,
);我好像不能完成这个任务,有什么帮助吗?
发布于 2012-01-28 05:22:18
默认情况下,当单选按钮作为单选按钮的一部分时,不会给出描述,但根据我在代码中看到的内容,您应该能够自己添加单选按钮。
$descriptions = array(...); // descriptions, indexed by key
foreach ($form['bedrijfsfiche']['#options'] as $key => $label) {
$form['bedrijfsfiche'][$key]['#description'] = $descriptions[$key];
}稍后,当单选按钮展开为单独的按钮时,它会将单个单选元素添加到这些数组$key位置,但它是通过追加来实现的,所以之前的任何内容都会保留下来。这意味着你可以添加描述,你自己,它们将停留在实际的单选按钮中。
发布于 2013-02-21 11:27:04
您需要为每个单选选项在表单数组中添加一个额外的键。表单数组的键应该是#options中可用选项的键,值应该是一个包含键#description和您想要提供的字符串的数组。
以字段为例,单选选项存储在$form' field _foo''# options‘中。如果#options数组的内容是('buyer‘=> 'Buyer','seller’=> 'Seller'),那么我们按如下方式添加描述。
// Since users and forms do not have language, use none.
$lang = LANGUAGE_NONE;
// Add descriptions to the radio buttons.
$form['field_foo'][$lang]['buyer'] = array(
'#description' => t('Are you a sommelier, wine director, or beverage manager?'),
);
$form['field_foo'][$lang]['seller'] = array(
'#description' => t('Are you a wine rep for a distributor, wholesaler, importer, or for a specific label?'),
);这有点奇怪,但它是有效的。:)
https://stackoverflow.com/questions/8969517
复制相似问题