I always enjoy Drupal Form API with the standard output, easy to use, and easy for extension. But sometime, due to special reason, you only want to display the form input itself, no wrapper div or label. In Drupal 7, it can be as simple as changing a boolean value, but for Drupal 6 it's a big trick. And here is the trick.
The main idea is all form element are run through theme_form_element, and this theme function adds label and wrapper to form output, so all we have to do is override this theme function to create an exception. Open your template.php in your theme and add the following code:
function themename_form_element($element, $value) { // This is also used in the installer, pre-database setup. $t = get_t(); if (empty($element['#no_wrapper'])) { $output = '<div class="form-item"'; if (!empty($element['#id'])) { $output .= ' id="'. $element['#id'] .'-wrapper"'; } $output .= ">\n"; $required = !empty($element['#required']) ? '<span class="form-required" title="'.
$t('This field is required.') .'">*</span>' : ''; if (!empty($element['#title'])) { $title = $element['#title']; if (!empty($element['#id'])) { $output .= ' <label for="'. $element['#id'] .'">'.
$t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required))
."</label>\n"; } else { $output .= ' <label>'. $t('!title: !required', array('!title' => filter_xss_admin($title),
'!required' => $required)) ."</label>\n"; } } $output .= " $value\n"; if (!empty($element['#description'])) { $output .= ' <div class="description">'. $element['#description'] ."</div>\n"; } $output .= "</div>\n"; } else { return $value; } return $output; } function _render_element(&$element) { $element['#no_wrapper'] = true; $result = drupal_render($element); return $result; }
No comments:
Post a Comment