Following the discussion "label tag has a forced break", I would like to make a proposal to improve the flexiblity of form-item styling one step further.
Rather than the #prefix and #suffix new attributes proposed by Zen in "label tag has a forced break" (update #9), I suggest to add #label and #format (names to be decided).
[I am new to PHP, so forgive me for my PHP errors in the following explanation. For example my syntax with '%name' is may be not appropriate]

#label would define how to format the label part. By default #label = '%title : %required'.
#format would define the format for the complete form-item. By default #format = '%label %value %description'.

For example one could define:

<?php
$form['example'] = array(
  '#type' => 'textfield', 
  '#title' => t('Subject'), 
  '#required' => TRUE,
  '#label' => '%required %title'
  '#format' => '%label %description %value'
);
?>

to suppress the (currently hardcoded) colon after the label, to put the required tag before the label and to put the description above the textfield.

For that function theme_form_element needs to be modified (something) like this:

function theme_form_element($title, $value, $description = NULL, $id = NULL, $required = FALSE, $error = FALSE, $label =  '%title : %required', $format = '%label %value %description') {

  $head  = '<div class="form-item">'."\n";
  $required = $required ? '<span class="form-required">*</span>' : '';

  if ($title) {
    if ($id) {
      $lab = ' <label for="'. form_clean_id($id) .'">'. interpret($label) ."</label>\n";
    }
    else {
      $lab = ' <label>'. $title .":$required</label>\n";
    }
  }

  $val = " $value\n";

  if ($description) {
    $descr= ' <div class="description">'. $description ."</div>\n";
  }

  $tail = "</div>\n";

  $output = $head . interpret($format) . $tail

  return $output;
}

Looking in the Drupal archives, I have seen that JohnG has made contributions in that area (see node/33850). m3avrck also suggested: "talk to berkes, he is a big advocate of this and has worked on it much more than I have". So if my proposal of adding two more attributes seems feasable, I believe that somebody will be able to propose a patch before I am ready myself to understand how implement the interpret() function.
Don't forget also to look at my other (complementary) proposal: "Allow flexible styling for form-item according to their type"

Comments

Montuelle’s picture

Oops, for a better understanding, I must rectify the above theme_form_element(). Of course for the label processing one must read:

    if ($id) {
      $label = ' <label for="'. form_clean_id($id) .'">'. interpret($label) ."</label>\n";
    }
    else {
      $label = ' <label>'. interpret($label) ."</label>\n";
    }
LAsan’s picture

Version: x.y.z » 7.x-dev

Feature request moving to cvs.

johnalbin’s picture

Status: Active » Closed (won't fix)

theme_form_element() has undergone major changes since then. See #43493: FAPI: Add name/type as CSS class for form elements for the latest round of proposed changes.

Also, we don't need to pass in the format for a label. If you want to modify the format, just create a theme override function in your theme. That's what theme functions are for.