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 )



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

  $items['testFormTemplate'] = array(
    'title' => t('Test form template'),
    'page callback' => 'mkl_variousTest_form_page',
    'access callback' => 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' => 'mkl_variousTest_formPage',
    'path' => drupal_get_path('module', 'mkl_variousTest') . '/templates',
    'variables' => array(
      'form' => drupal_get_form('mkl_variousTest_form'),

  return $themes;

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

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

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

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

  return $form;

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


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 : error 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 :


<?php print drupal_render_children($form); ?>

  • Has it started looping infinitely when you added the date_popup field? Have you tried removing it? Are you sure it's got to do with the date_popup? What's in your mkl-variousTest-formPage.tpl.php template file?
    – Beebee
    Jan 20, 2014 at 12:47
  • hello Beebee, yes it is starting looping infinitely when I had the date_popup field. yes I have tried to remove it and it works fine. yes I'm sure the problem is about the date_popup field. I will update my post to add the template file now, but it is a very basic one too.
    – tyd01
    Jan 20, 2014 at 13:10

1 Answer 1


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' => $form));

Your Answer

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

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