hook_form_alter setting select list #options key allow attributes per option I have a select list that I am populating $form['field_my_field']['und']['#options'] in a hook_form_alter.

I was wondering what a good way to set a data attribute per each option would be. I've thought about adding some inline javascript to add it after it's rendered, but I want to do this with PHP and preferably within the hook_form_alter.

Is this possible?
Based on theme_select which is the one that constructs and styles the Drupal Form API's select type. It uses the form_select_options function do create the &lt;option&gt; tags.

So you would need to override theme_select and replace the form_select_options function with your own.

Basically, copy the functions and it's content, rename them and do your modifications.