Multiple forms on the same page: hook_forms only works after cache_clear_all In a User Tab there are multiple node forms of the same type. 

To do this I implemented hook_forms. Multiple forms are shown and they work (sometimes).
But if the user adds some (or delete) nodes and calls his page again he gets the following error:

(Lets say the user owns node 1 and 2)


  Notice: Undefined index: mymodule_a_form_1 in drupal_retrieve_form() (Zeile 738 von /htdocs/includes/form.inc).
  
  Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'mymodule_a_form_1' was given in drupal_retrieve_form() 
  (Zeile 773 von /htdocs/includes/form.inc).
  
  Notice: Undefined index: mymodule_a_form_2 in drupal_retrieve_form() (Zeile 738 von /htdocs/includes/form.inc).
  Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'mymodule_a_form_2' was given in drupal_retrieve_form() 
  (Zeile 773 von /htdocs/includes/form.inc).


The forms work again if I clear all caches. 

So what is wrong with this (sample) code?:

&lt;?php

function mymodule_user_profile_tab_content($uid) {
  $out = array();
  $users_node_ids = _get_user_node_ids();
  foreach($users_node_ids as $nid) {
    $node = node_load($nid);
    $out[] = drupal_get_form('mymodule_a_form_'.$nid, array('node' =&gt; $node));
  }
  return $out;
}

/**
 * Implementation of hook_forms()
 */
function mymodule_forms($form_id, $args) {
  $forms = array();
  if (strpos($form_id, 'mymodule_a_form_') === 0) {
    $forms[$form_id] = array(
      'callback' =&gt; 'mymodule_a_form',
    );
  }
  return $forms;
}
I had the same problem and it seemed to be resolved after correcting an issue with the function definition. Make sure that $form_state is a reference.

function mymodule_a_form($form_id, &amp;$form_state, $args) {
...
}


One of the other things that I noticed is that the cached module_implements no longer had a reference to my module, so when Drupal was looping through the implements and looking for a function called mymodule_forms(), it couldn't find it.  You can check to see if this is the issue by comparing the cached implements to the static version.

    $cache_implements = cache_get('module_implements', 'cache_bootstrap')-&gt;data['forms'];
    ksort($cache_implements);
    dpm($cache_implements, 'CACHED FORM IMPLEMENTS');

    $static_implements = drupal_static('module_implements');
    ksort($static_implements);
    dpm($static_implements['forms'], 'STATIC FORM IMPLEMENTS');


If that is the issue and your form declaration is correct then maybe try doing an include on the page that references your dynamic forms.

module_load_include('admin', 'mymodule', 'inc');