正确答案
您需要重写主题template.php中的theme_form_element以更改表单字段描述的顺序。请参阅下面的代码,它将更改所有字段的顺序。
如果你只想改变一个字段,然后通过检查$ element数组只为你的字段添加一个if条件!
function yourtheme_form_element($variables) {
$element = &$variables['element'];
// This is also used in the installer, pre-database setup.
$t = get_t();
// This function is invoked as theme wrapper, but the rendered form element
// may not necessarily have been processed by form_builder().
$element += array(
'#title_display' => 'before',
);
// Add element #id for #type 'item'.
if (isset($element['#markup']) && !empty($element['#id'])) {
$attributes['id'] = $element['#id'];
}
// Add element's #type and #name as class to aid with JS/CSS selectors.
$attributes['class'] = array('form-item');
if (!empty($element['#type'])) {
$attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
}
if (!empty($element['#name'])) {
$attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
}
// Add a class for disabled elements to facilitate cross-browser styling.
if (!empty($element['#attributes']['disabled'])) {
$attributes['class'][] = 'form-disabled';
}
$output = '<div' . drupal_attributes($attributes) . '>' . "\n";
// If #title is not set, we don't display any label or required marker.
if (!isset($element['#title'])) {
$element['#title_display'] = 'none';
}
$prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
$suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
$element_description = "";
if (!empty($element['#description'])) {
$element_description = '<div class="description">' . $element['#description'] . "</div>\n";
}
switch ($element['#title_display']) {
case 'before':
case 'invisible':
$output .= ' ' . theme('form_element_label', $variables);
$output .= $element_description;
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
break;
case 'after':
$output .= ' ' . $prefix . $element['#children'] . $suffix;
$output .= ' ' . theme('form_element_label', $variables) . "\n";
break;
case 'none':
case 'attribute':
// Output no label and no required marker, only the children.
$output .= $element_description;
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
break;
}
$output .= "</div>\n";
return $output;
}
其他方式和简单的方法来解决这个问题是使用jQuery来改变位置。这将帮助你!
$form['a'] = array('#type'=>'checkbox','#description'=>'hello');
:描述从来没有使它到html)。评论时间70年01月01日原作者 : Shawn$output .= $element_description;
在结束时添加case 'after':
- Shawn在 10月22日在15:31