I want to change the way Drupal builds specific fields on a specific node edit/add form on my site. For example, when I use print drupal_render($form['textarea']); in my node--CONTENTTYPE--form.tpl.php file, I get the default Drupal render of the field widget. I want to modify the HTML markup of the field widget.

There are three ways I can think of that might solve this problem:

  1. Using a forms equivalent of the theme_field() hook. This seems ideal, but after searching for the last few hours, I haven't found anything on this.

  2. Building custom field widgets for every field type I'm using on that node. This is definitely not ideal and I have to believe there's an easy way to do this in Drupal from a theme point of view.

  3. Manually build the HTML markup for the form and field in node--CONTENTTYPE--form.tpl.php with print $form['textarea']['und'][0]['title']; and the like.

Is there a hook in Drupal to do this, or must the code for every field I want to modify be manually generated?

1 Answer 1


I think your third option is the most direct solution since you are only looking to change one form and that file will only be called when you use that form.

The only alternative I can think of is to use hook_form_FORM_ID_alter and iterate through the form items, putting html into the #prefix and #suffix values; or creating #attribute['class'] or #attribute['style'] values depending on what you are trying to achieve.

  • When using a form override template, does Drupal still automatically add in the validation checks, or would I have to use drupal_render($form['formfield']); to add each field with the associated validations? The question I think I'm asking is: does a form override template modifying underlying field behavior or only the appearance of that instance? Commented Sep 8, 2014 at 13:27
  • If by form override template you mean the use of hook_form_alter and its brethren, then Drupal will do everything it normally does including the validation. You can adjust the validation in the hook if you want to but you don't have to.
    – Darvanen
    Commented Oct 3, 2014 at 4:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.