date_popup + theme = infinite loop I'm trying to create a templated form including date_popup field in a custom module. There is a very basic example : mkl_variousTest.module ( dependency : date_popup from date API )

&lt;?php

//mkl_variousTest.module

/**
 * Implementation of hook_menu()
 * @return array
 */
function mkl_variousTest_menu() {
  $items = array();

  $items['testFormTemplate'] = array(
    'title' =&gt; t('Test form template'),
    'page callback' =&gt; 'mkl_variousTest_form_page',
    'access callback' =&gt; TRUE,
  );

  return $items;
}

/**
 * Implementation of hook_theme($existing, $type, $theme, $path)
 * @param array $existing
 * @param string $type
 * @param string $theme
 * @param string $path
 * @return array
 */
function mkl_variousTest_theme($existing, $type, $theme, $path) {
  $themes = array();

  $themes['formPage'] = array(
    'template' =&gt; 'mkl_variousTest_formPage',
    'path' =&gt; drupal_get_path('module', 'mkl_variousTest') . '/templates',
    'variables' =&gt; array(
      'form' =&gt; drupal_get_form('mkl_variousTest_form'),
    ),
  );

  return $themes;
}

/**
 * Implementation of hook_form($form, &amp;$formState)
 * @param node $node
 * @param array $formState
 * @return array
 */
function mkl_variousTest_form($node, &amp;$formState) {
  $form = array();

  $form['name'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('Nom'),
    '#lenght' =&gt; 60,
    '#required' =&gt; TRUE,
  );

  $form['date'] = array(
    '#type' =&gt; 'date_popup',
    '#title' =&gt; t('date'),
  );

  $form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('OK'),
  );

  return $form;
}

function mkl_variousTest_form_page() {
  return theme('formPage');
}

?&gt;


Using this way, drupal run in an infinite loop and return this error : 


  Fatal error: Maximum function nesting level of '100' reached,
  aborting!


There is a printScreen :


Next, the same function calls between #19 to #37 are repeated until drupal stop the loop.
This append as soon as I have a date_popup field in my form.

So how can I fix it ?

PS : This is my template file mkl_variousTest_formPage.tpl.php :

&lt;p&gt;before&lt;/p&gt;

&lt;?php print drupal_render_children($form); ?&gt;

&lt;p&gt;after&lt;/p&gt;
Stab in the dark, but I think your problem is probably stemming from the fact that you're building the form from within a theme function, which in turn calls another theme function, then so on and so forth. Logically theming should be after you've built the form.

Replace drupal_get_form('mkl_variousTest_form') in hook_theme() to NULL and in your page callback add the following code.

$form = drupal_get_form('mkl_variousTest_form');
return theme('formPage', array('form' =&gt; $form));