Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.491
diff -u -p -r1.491 form.inc
--- includes/form.inc	13 Sep 2010 01:09:25 -0000	1.491
+++ includes/form.inc	14 Sep 2010 01:41:16 -0000
@@ -933,34 +933,37 @@ function drupal_prepare_form($form_id, &
   // theme_form() itself is in #theme_wrappers and not #theme. Therefore, the
   // #theme function only has to care for rendering the inner form elements,
   // not the form itself.
-  drupal_theme_initialize();
-  $registry = theme_get_registry();
-  // If #theme has been set, check whether the theme function(s) exist, or
-  // remove the suggestion(s), so drupal_render() renders the children.
-  if (isset($form['#theme'])) {
-    if (is_array($form['#theme'])) {
-      foreach ($form['#theme'] as $key => $suggestion) {
-        if (!isset($registry[$suggestion])) {
-          unset($form['#theme'][$key]);
+  // Programmatically submitted forms do not have any use for a theme.
+  if (!$form_state['programmed']) {
+    drupal_theme_initialize();
+    $registry = theme_get_registry();
+    // If #theme has been set, check whether the theme function(s) exist, or
+    // remove the suggestion(s), so drupal_render() renders the children.
+    if (isset($form['#theme'])) {
+      if (is_array($form['#theme'])) {
+        foreach ($form['#theme'] as $key => $suggestion) {
+          if (!isset($registry[$suggestion])) {
+            unset($form['#theme'][$key]);
+          }
+        }
+        if (empty($form['#theme'])) {
+          unset($form['#theme']);
         }
       }
-      if (empty($form['#theme'])) {
-        unset($form['#theme']);
+      else {
+        if (!isset($registry[$form['#theme']])) {
+          unset($form['#theme']);
+        }
       }
     }
+    // Only try to auto-suggest theme functions, if #theme has not been set.
     else {
-      if (!isset($registry[$form['#theme']])) {
-        unset($form['#theme']);
+      if (isset($registry[$form_id])) {
+        $form['#theme'] = $form_id;
+      }
+      elseif (isset($form_state['build_info']['base_form_id']) && isset($registry[$form_state['build_info']['base_form_id']])) {
+        $form['#theme'] = $form_state['build_info']['base_form_id'];
       }
-    }
-  }
-  // Only try to auto-suggest theme functions, if #theme has not been set.
-  else {
-    if (isset($registry[$form_id])) {
-      $form['#theme'] = $form_id;
-    }
-    elseif (isset($form_state['build_info']['base_form_id']) && isset($registry[$form_state['build_info']['base_form_id']])) {
-      $form['#theme'] = $form_state['build_info']['base_form_id'];
     }
   }
 
