09
Nov
Creating a theme for a form in Drupal 6 is slightly different from Drupal 5.
Steps on how to theme a form in Drupal 6:
- Register the theme file.
Use the hook_theme() function to register the theme for the form. More information on hook_theme() can be got from here: http://api.drupal.org/api/function/hook_themeNOTE: myform1_form and myform2_form are the form ids of the forms you want to themefunction mymodule_theme() { $themes = array( 'myform1_form' => array( 'arguments' => array('form'), 'function' => 'mytheme_myform1_form', ), 'myform2_form' => array( 'arguments' => array('form'), 'function' => 'mytheme_myform2_form', ), ); return( $themes ); } - Define the callback function. Pass parameters to the theme file and render the file.
function mytheme_ myform1_form($form) { drupal_add_css(drupal_get_path('module', 'mymodule') .'/mymodule-form.css'); drupal_add_js(drupal_get_path('module', 'mymodule') .'/mymodule-form.js'); return theme_render_template(path_to_theme() . '/mytemplate.tpl.php', array('form' => $form)); }NOTE: It is important to pass the form parameter to the template file as array('form' => $form) instead of directly passing $formFor more information on theme_render_template() check this http://api.drupal.org/api/function/theme_render_template/6
- Template file.
<div class="onelinedd"> <div class="onedd"> <div class="labels"> <div>Form Field 1</div> <?php echo drupal_render($form['form_field_1']); ?> </div> </div> <div class="onedd"> <div class="labels"> <div>Form Field 2</div> <?php echo drupal_render($form['form_field_2']); ?> </div> </div> <div class="onedd"> <?php echo drupal_render($form['submit']); ?> </div> </div>
- Clear cache. Admin -> Site Configuration -> Performance -> Clear Cache
I am sure there must be an better way to do this but, after hours of searching and trying this is what worked for me!
Tips on how to theme a form were taken from these links:
http://agaric.com/note/how-theme-drupal-form




