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 http://11heavens.com/theming-the-contact-form-in-Drupal-6
For the bare minimum, read on:
<?php
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).
<?php
/**
* 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.
Comments
Post new comment