【发布时间】:2014-05-14 10:54:52
【问题描述】:
我想设置我正在使用表单 API 在模块中创建的表单元素的 ID 属性。
【问题讨论】:
标签: drupal drupal-7 drupal-fapi
我想设置我正在使用表单 API 在模块中创建的表单元素的 ID 属性。
【问题讨论】:
标签: drupal drupal-7 drupal-fapi
//Here is an example
$form['name'] = array(
'#type' => 'item',
'#title' => t('Title'),
'#attributes' => array(
'id' => 'your-id',
),
);
【讨论】:
使用#id property:
$form['foo'] = array(
'#type' => 'textfield',
'#title' => t('Bar'),
'#id' => 'baz',
);
为确保唯一性,您可能应该在 ID 字符串上使用 drupal_html_id()。
【讨论】: