Moving the help text in forms

Posted by emmajane on September 27, 2008 - 1:17am in

In Szeged at William Lawrence's session on Accessibility Best Practices in Drupal Theming we talked about moving the form "help" text so that it was between the form label and the form widget (by default it's below). We also talked about having a control option (per field) that would allow you to select whether the help text was displayed above or below the form widget.

My forms now look like this:

 

I didn't get the control working, but with the help of chx and moonshine on IRC I was able to get the help text to appear above the form widgets instead of their default location, below. I correctly identified the function that controls "regular" form elements, but I was having a hard time tracking down the function for multiple form elements (used for CCK imagefield with lots of images uploaded). They pointed me in the right direction! Yay! If you want to get this working on your site too you need to copy two functions into your theme's template.php file and adjust the output as described below.

Regular form elements

Function used: theme_form_element

What you need to change: swap the $value and the "description" output lines so that the description is attached to $output ahead of $value.

 

Multiple form values (e.g. imagefield)

Function used: theme_content_multiple_values

What you need to change: move $description from the bottom (ish) of the function to the top. Add the $description to the $header via the data array key. Like this:

'data' => t('!title: !required', array('!title' => $element['#title'], '!required' => $required)).$description,

 

Update I have also created a feature request to have this as a toggle option when new content fields are created.

Comments

Leave your feedback at the bottom. Comments may be held in moderation.

Post new comment
The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span> <img> <blockquote> <b> <i>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.