Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ctools/includes/form.inc,v
retrieving revision 1.11
diff -u -p -r1.11 form.inc
--- includes/form.inc	13 Aug 2009 22:24:02 -0000	1.11
+++ includes/form.inc	18 Jun 2010 20:16:05 -0000
@@ -126,9 +126,15 @@ function ctools_build_form($form_id, &$f
   // workflow is NOT complete. We need to construct a fresh copy of
   // the form, passing in the latest $form_state in addition to any
   // other variables passed into drupal_get_form().
+  //
+  // If this function is being used to perform an '#ahah' callback
+  // to rebuild some or all of a ctools wizard form step, be sure that
+  // $form_state['wrapper callback'], $form_state['form_info'],
+  // $form_state['step'], $form_state['no_redirect'], and $form_state['rebuild']
+  // are properly set.
 
   if (!empty($form_state['rebuild']) || !empty($form_state['storage'])) {
-    $form = ctools_rebuild_form($form_id, $form_state, $args);
+    $form = ctools_rebuild_form($form_id, $form_state, $args, $_POST['form_build_id']);
   }
 
   // If whoever is calling this wants the $form array (so that it can render it
@@ -168,7 +174,21 @@ function ctools_rebuild_form($form_id, &
   $args[0] = &$form_state; // Replaces placeholder.
   // And the form_id.
   array_unshift($args, $form_id);
-  $form = call_user_func_array('drupal_retrieve_form', $args);
+
+  if (isset($form_state['wrapper callback']) && function_exists($form_state['wrapper callback'])) {
+    // If there is a wrapper callback, we do not use drupal_retrieve_form.
+    // Instead, we call $form_id builder function directly. This means the args
+    // are *different* for forms used this way, which may not be ideal but
+    // is necessary right now.
+    $form = array();
+    $form_state['wrapper callback']($form, $form_state);
+    if (function_exists($form_id)) {
+      $form_id($form, $form_state);
+    }
+  }
+  else {
+    $form = call_user_func_array('drupal_retrieve_form', $args);
+  }
 
   if (!isset($form_build_id)) {
     // We need a new build_id for the new version of the form.
