Form element titles and the invisible #title_display property

Benjamin Melançon's picture
Submitted by Benjamin Melançon on 2010, October 17 - 15:32
  • Note: Forms are made to look how they are at two layers, the Forms API and the theme layer.

    [Words below are mostly Everett's verbatim]

    Drupal 7 provides a #title_display property that can be used with any form element that supports the #title property. The #title_display property tells the form system how to render #title

    before
    (default) #title is rendered as a label element before the form element in the page markup.
    after
    (default value for radio and checkbox form element types.)
    #title is rendered as a label element after the form element in the page markup.
    invisible
    #title is rendered as a label element before the form element in the page markup, and is made invisible with the Drupal 7 .element-invisible CSS class. This makes #title remain available to screen-reader users, but hides it from being displayed visually in the browser.

    Tip We should never unset a title. Per accessibility standards, every form element requires "text by which software can identify a component within Web content to the user" (http://www.w3.org/TR/2008/REC-WCAG20-20081211/#namedef).

    There is one more possible setting for #title_display that works only for radio and checkbox elements.

    attribute
    #title is rendered as the title attribute of the form element

    Read more about this property and its role in accessibility at Everett Zufelt's blog post, http://zufelt.ca/blog/drupal-7-form-api-accessibility-titledisplay

  • Explanation

  • In the intro to module development i guess...
  • Book element

  • How to