I want to set the ID attribute of an element of a form that I'm creating in a module using the form API.
How can I set ID attribute for drupal 7 form elements?
7.1k Views Asked by Peiman Noroozi At
2
There are 2 best solutions below
0
On
Use the #id property:
$form['foo'] = array(
'#type' => 'textfield',
'#title' => t('Bar'),
'#id' => 'baz',
);
To ensure uniqueness you should probably use drupal_html_id() on the ID string.