开发者

How to swap textfield and its label in Drupal

开发者 https://www.devze.com 2023-03-17 17:16 出处:网络
I\'m using drupal_render() to render forms. By default, it renders a label and then a textfield. How can I change this so that the t开发者_开发知识库extfield is shown first?In Drupal 6:

I'm using drupal_render() to render forms. By default, it renders a label and then a textfield. How can I change this so that the t开发者_开发知识库extfield is shown first?


In Drupal 6: You could implement hook_form_alter() and assign a custom function to the #theme attribute of whatever element you want to modify. Then when Drupal wants to render that element, it will call your function, instead of theme_form_element().

Or you could override the theme_form_element() function by copying it to your template.php and renaming it to mytheme_form_element(). Then you can totally modify the way form elements are rendered. Note that all form elements are rendered through it, so you're gonna want to check for $element['#name'] so that you only override the output for just the specific elements you need (and this is why doing a hook_form_alter() is a "cleaner" way to do this).

And don't forget to clean the cache whenever your theming modifications don't seem to do anything! :>


Typically you'd handle that kind of overriding at the theme layer. To find out what function or file is generating the output in question, you can use the Theme Developer module. Then override as needed.


You can override field.tpl.php in Drupal 7 and change the position of $label where you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消