Is there a straightforward way to reposition the "help" or "description" text that is routinely displayed *after* a field on a form so that it appears directly below the field title?

Comments

eliza411’s picture

In case others are trying to do this, I succeeded by adding the following lines to my template.php file:

  function phptemplate_form_element($title, $value, $description = NULL, $id = NULL, $required = FALSE, $error = FALSE) {
    return _phptemplate_callback('form_element', array('value' => $value, 'title' => $title, 'description' => $description,
    'id' => $id, 'required' => $required, 'error' => $error));
  }

And then creating a form_element.tpl.php file that looked like:

<?
/**
 * Return a themed form element.
 *
 * @param $title the form element's title
 * @param $value the form element's data
 * @param $description the form element's description or explanation
 * @param $id the form element's ID used by the &lt;label&gt; tag
 * @param $required a boolean to indicate whether this is a required field or not
 * @param $error a string with an error message filed against this form element
 *
 * @return a string representing the form element
 */

?>
<div class="form-item">
<?
  $required = $required ? '<span class="form-required" title="'. t('This field is required.') .'">*</span>' : '';

  if ($title) {
    if ($id) {
      print ' <label for="'. form_clean_id($id) .'">'. t('%title: %required', array('%title' => $title, '%required' =>
      $required)) . "</label>\n";
    }
    else {
      print  ' <label>'. t('%title: %required', array('%title' => $title, '%required' => $required)) . "</label>\n";
    }
  }

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

  print  " $value\n";
?>
</div>
emilyf’s picture

I just wanted to say thanks for this! Works excellent with Drupal 4.7.6 and webform module. Great code.

ycim’s picture

After searching for this for HOURS today, this code worked FABULOUS, and it was up and working in under 2 minutes!

Thank you so much!

dmweyer’s picture

Where should the form_element.tpl.php file be saved? Same folder as template.php? O and is the template.php file that you need to edit the one specific to the template you have applied to the site?

Dill

eliza411’s picture

I saved the form_element.tpl.php file in the same folder as the template.php file and the template.php is the base file that holds all your functions, literally template.php, not one of the tpl.php files.

Hope that helps.

dmweyer’s picture

Tried this, but if I have the form_element.tpl.php in my theme folder the webform field name stop showing??

Lakewood’s picture

>Is there a straightforward way to reposition
>the "help" or "description" text that is routinely
>displayed *after* a field on a form so that it
>appears directly below the field title?

I tried eliza411's solution in 6.6. Didn't work. Any programmers out there willing to whip up a version of this for D6? I need to have help text above the text boxes in forms. People sometimes don't see the help text at the bottom on big text areas.

adshill’s picture

I could also really no with help on this if anyone can!

Thanks

Adam

hintbw’s picture

sheldon rampton’s picture

I've just written a module for Drupal 7 that offers a solution to this problem:

http://drupal.org/project/label_help

----------------
Customer Support Engineer, Granicus
https://granicus.com