Apparently you can group options together with headings in a SELECT form element. This is not mentioned at all in the Form API reference document.

Here's an example of an array that works:

  $options = array(
    'Group 1' => array(
      'a' => t('Option A'),
      'b' => t('Option B'),
    ),
    'Group 2' => array(
      'x' => t('Option X'),
      'y' => t('Option Y'),
    ),
  );

Headings appear in bold italic and are not selectable by the user.

Details here: http://drupal.org/node/76500#comment-3451808

Comments

jhodgdon’s picture

Component: Missing documentation » API documentation files
Issue tags: +FAPI reference

Presumably you are asking for this to be added to the Form API reference that appears on api.drupal.org?

joachim’s picture

Hmmmmyes... sorry I have now lost track of where documentation bugs are meant to be reported!

jhodgdon’s picture

You got it to the right project. Adding a URL of the page that needs updating is always helpful. :)

Do you know which versions of Drupal the above applies to, by the way?

joachim’s picture

My example code works on D7.

The forum post I linked to is about D6, but I've not tested it myself.

It's probably not worth bothering about D5 :)

(Sorry, I spend so long reading parts of that Form API reference I assume everyone else does too...)

jhodgdon’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)

This is a duplicate of #2283703: Document how optgroups work on 'select' form elements -- which is newer, but it is using the standard terminology so I'd prefer to keep it open rather than this one.