I want to render drupal 6 form through tpl file. for that 1. I have written mytheme_theme in template.php file and there I have define my template forms arguments and path for tpl file.

  1. I have written tpl file

  2. in form function at the end I have called theme by '#theme' => 'my_template'

doing all these thing my from is rendering through tpl but now its not going into submit_hander() and validation.

can any one help me these? I am not getting what's wrong in these.

see in my template.php contain:

function cs_theme(&$existing, $type, $theme, $path) {
  $hooks = zen_theme($existing, $type, $theme, $path);
  // Add your theme hooks like this:
  $hooks['hook_name_here'] = array( // Details go here );

  // @TODO: Needs detailed comments. Patches welcome!

  $hooks['my_theme_example'] = array(
                  'arguments' => array(
                  'order' => null, 
                  'render element' => 'form',
                 'template' => 'mymodule_template',
                 'path' => drupal_get_path('theme', 'theme_name') . '/templates',

  return $hooks;

In these way I have printed all the form fields in my .tpl file is:

   <?php print drupal_render($variables['order']['logo']);?>
  • Change theme hook definition for the form in hook_registry_alter().
    – FriOne
    Aug 11, 2014 at 7:31
  • can u plez explain in more detail?
    – mathili
    Aug 11, 2014 at 7:37
  • Zz.. So hard to help you) Do you have '<form ' . $action . ' accept-charset="UTF-8" method="' . $element['#method'] . '" id="' . $element['#id'] . '"' . drupal_attributes($element['#attributes']) . "> in your template?
    – FriOne
    Aug 11, 2014 at 11:42
  • Can we attach files here so that you can view my code and then you can help me
    – mathili
    Aug 12, 2014 at 12:46

1 Answer 1


You need rewrite 'form' like this:

 * Implements hook_theme_registry_alter().
function mymodule_theme_registry_alter(&$theme_registry) {
  $form_registry = &$theme_registry['form'];
  $form_registry['function'] = 'mymodule_form_theme';
function mymodule_form_theme($element) {
  // I'm not sure that $element has 'from_id' but you could pass it if you need.
  if ($element['form_id'] == 'yours_form_id') {
    return theme_form($element);
  // Else return what you need I guess that better to use hook_theme()
  // and then call theme() function.

Look at theme_form() to understand what variables need to pass in form tag. I don't understand why do you need this. What is the reason to use template file?

  • thanks for reply. i have written hook_theme() in .module file. but thn also its going into submit hander. is anything miss by me?
    – mathili
    Aug 11, 2014 at 8:06
  • Describe what you need at the end. Do you need simple form without Drupal Form API? Or you need change submit handler? Or what else?
    – FriOne
    Aug 11, 2014 at 8:11
  • I have created custom form and for that I have written submit_handler() and validation, the form was working fine without writing anything in tpl, template file. but there is requirement that form should be render through template file, so I have done all thing which mention above but now its not going into submit_handler(). I want the form should go into submit_handler() and the form should render through template.
    – mathili
    Aug 11, 2014 at 8:20
  • Show your template file in your question. Also, do you get form content throw drupal_get_form() function?
    – FriOne
    Aug 11, 2014 at 8:22
  • I am getting form content through tpl file but only prob is that it is not going in submit_handler()
    – mathili
    Aug 11, 2014 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.