Search code examples
drupaldrupal-6drupal-theming

How to display a custom form in a newly created template page


I do have a hook_form in my custom module and also have a customized page.tpl.php file .Is there any way by which you can pass the form to the tpl page.I thought of passing the $form variable to the tpl page through the hook_theme function but that is quite not working.


Solution

  • The standard method is to use a preprocess function, either in your theme or module

    function MYMODULE_preprocess_page(&$vars) {
      $vars['some_form'] = drupal_get_form('MYMODULE_some_form');
    }
    

    Then in the template file:

    <?php echo $some_form; ?>
    

    You'll need to clear the caches after implementing the hook for the theme registry to pick it up.