How to theme a form in Drupal6 with Drupal Form API

Drupal provide a Form API to let us make a form. That is a right way to do that.

By default, it create a form element in html like this:

But how to add some custom html or class into it?

You can use ‘#prefix’ or ‘#suffix’ to wrap your custom html outside the default in hook_form() when add a form element. But a more powerful way is using theme_form_element().

For drupal6, just copy the original function code:

Then add your own hook function into theme template file. For example:

That’s it.

Leave a Reply