User login

How to theme a form in Drupal 6

Theming a form, like theming almost anything in Drupal 6, requires registering the theme function with hook_theme in a module or a theme. The FormAPI docs and the Drupal 5.x to Drupal 6.x form upgrade guide (Drupal 5.x to 6.x FormAPI changes appear to remain a little deficient in explaining this.

See for instance How to theme a form in Drupal 6.x?

For a more thorough overview of form theming, see

For the bare minimum, read on:

function example_trial_reg_form() {   
  $form = array();
  $form['example'] = array(
    '#value' => t("Please complete our short registration form."),
  return $form;

You have a nice function called theme_example_trial_reg_form($form) for it but nothing happens, it isn't called.

Split theming into a template file and added the requisite theme_form hook to template.php (needed even without a template file).

 * Implementation of hook_theme() for a zen subtheme.
function example_theme(&$existing, $type, $theme, $path) {
  $hooks = zen_theme($existing, $type, $theme, $path);
  $hooks['genarts_trial_reg_form'] = array(
    'arguments' => array('form' => NULL),
    'template' => 'genarts-trial-reg-form',
  return $hooks;

Since we have to go as far as making a hook_theme implementation, might as well make the template file approach anyway.

You do not have to create a preprocess function to receive the $form variable.

Searched words: 
drupal 6 form theme function not called


Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.