Index: modules/book/book.pages.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/book/book.pages.inc,v
retrieving revision 1.5
diff -u -p -r1.5 book.pages.inc
--- modules/book/book.pages.inc	22 Dec 2007 23:24:24 -0000	1.5
+++ modules/book/book.pages.inc	25 Feb 2008 03:19:04 -0000
@@ -231,10 +231,12 @@ function book_remove_form_submit($form, 
  *   Prints the replacement HTML in JSON format.
  */
 function book_form_update() {
-  $cid = 'form_'. $_POST['form_build_id'];
-  $bid = $_POST['book']['bid'];
-  $cache = cache_get($cid, 'cache_form');
-  if ($cache) {
+  if (isset($_POST['form_build_id']) && isset($_POST['book']['bid'])) {
+    $cid = 'form_'. $_POST['form_build_id'];
+    $bid = $_POST['book']['bid'];
+    $cache = cache_get($cid, 'cache_form');
+  }
+  if (!empty($cache)) {
     $form = $cache->data;
 
     // Validate the bid.
@@ -251,13 +253,10 @@ function book_form_update() {
       $form = form_builder($form['form_id']['#value'] , $form, $form_state);
       $output = drupal_render($form['book']['plid']);
       drupal_json(array('status' => TRUE, 'data' => $output));
+      exit();
     }
-    else {
-      drupal_json(array('status' => FALSE, 'data' => ''));
-    }
-  }
-  else {
-    drupal_json(array('status' => FALSE, 'data' => ''));
   }
+  // We only get here if there was an error or invalid data in $_POST
+  drupal_json(array('status' => FALSE, 'data' => ''));
   exit();
 }
Index: modules/poll/poll.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/poll/poll.module,v
retrieving revision 1.264
diff -u -p -r1.264 poll.module
--- modules/poll/poll.module	20 Feb 2008 13:46:40 -0000	1.264
+++ modules/poll/poll.module	25 Feb 2008 03:19:04 -0000
@@ -117,6 +117,7 @@ function poll_menu() {
     'page callback' => 'poll_choice_js',
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
+    'file' => 'poll.pages.inc',
   );
 
   return $items;
@@ -330,43 +331,6 @@ function _poll_choice_form($delta, $valu
 }
 
 /**
- * Menu callback for AHAH additions.
- */
-function poll_choice_js() {
-  $delta = count($_POST['choice']);
-
-  // Build our new form element.
-  $form_element = _poll_choice_form($delta);
-  drupal_alter('form', $form_element, array(), 'poll_choice_js');
-
-  // Build the new form.
-  $form_state = array('submitted' => FALSE);
-  $form_build_id = $_POST['form_build_id'];
-  // Add the new element to the stored form. Without adding the element to the
-  // form, Drupal is not aware of this new elements existence and will not
-  // process it. We retreive the cached form, add the element, and resave.
-  $form = form_get_cache($form_build_id, $form_state);
-  $form['choice_wrapper']['choice'][$delta] = $form_element;
-  form_set_cache($form_build_id, $form, $form_state);
-  $form += array(
-    '#post' => $_POST,
-    '#programmed' => FALSE,
-  );
-
-  // Rebuild the form.
-  $form = form_builder('poll_node_form', $form, $form_state);
-
-  // Render the new output.
-  $choice_form = $form['choice_wrapper']['choice'];
-  unset($choice_form['#prefix'], $choice_form['#suffix']); // Prevent duplicate wrappers.
-  $choice_form[$delta]['#attributes']['class'] = empty($choice_form[$delta]['#attributes']['class']) ? 'ahah-new-content' : $choice_form[$delta]['#attributes']['class'] .' ahah-new-content';
-  $choice_form[$delta]['chvotes']['#value'] = 0;
-  $output = theme('status_messages') . drupal_render($choice_form);
-
-  drupal_json(array('status' => TRUE, 'data' => $output));
-}
-
-/**
  * Implementation of hook_submit().
  */
 function poll_node_form_submit(&$form, &$form_state) {
Index: modules/poll/poll.pages.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/poll/poll.pages.inc,v
retrieving revision 1.4
diff -u -p -r1.4 poll.pages.inc
--- modules/poll/poll.pages.inc	14 Dec 2007 09:50:41 -0000	1.4
+++ modules/poll/poll.pages.inc	25 Feb 2008 03:19:04 -0000
@@ -54,3 +54,50 @@ function poll_results($node) {
   $node->show_results = TRUE;
   return node_show($node, 0);
 }
+
+/**
+ * Menu callback for AHAH additions.
+ */
+function poll_choice_js() {
+  if (isset($_POST['choice']) && isset($_POST['form_build_id'])) {
+    $delta = count($_POST['choice']);
+  
+    // Build our new form element.
+    $form_element = _poll_choice_form($delta);
+    drupal_alter('form', $form_element, array(), 'poll_choice_js');
+  
+    // Build the new form.
+    $form_state = array('submitted' => FALSE);
+    $form_build_id = $_POST['form_build_id'];
+    // Add the new element to the stored form. Without adding the element to the
+    // form, Drupal is not aware of this new elements existence and will not
+    // process it. We retreive the cached form, add the element, and resave.
+    $form = form_get_cache($form_build_id, $form_state);
+  }
+  if (!empty($form)) {
+    $form['choice_wrapper']['choice'][$delta] = $form_element;
+    form_set_cache($form_build_id, $form, $form_state);
+    $form += array(
+      '#post' => $_POST,
+      '#programmed' => FALSE,
+    );
+  
+    // Rebuild the form.
+    $form = form_builder('poll_node_form', $form, $form_state);
+  
+    // Render the new output.
+    $choice_form = $form['choice_wrapper']['choice'];
+    unset($choice_form['#prefix'], $choice_form['#suffix']); // Prevent duplicate wrappers.
+    $choice_form[$delta]['#attributes']['class'] = empty($choice_form[$delta]['#attributes']['class']) ? 'ahah-new-content' : $choice_form[$delta]['#attributes']['class'] .' ahah-new-content';
+    $choice_form[$delta]['chvotes']['#value'] = 0;
+    $output = theme('status_messages') . drupal_render($choice_form);
+    if ($output) {
+      drupal_json(array('status' => TRUE, 'data' => $output));
+      exit();
+    }
+  }
+  // We only get here if there was an error or invalid data in $_POST
+  drupal_json(array('status' => FALSE, 'data' => ''));
+  exit();
+}
+
Index: modules/upload/upload.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/upload/upload.module,v
retrieving revision 1.199
diff -u -p -r1.199 upload.module
--- modules/upload/upload.module	20 Feb 2008 13:46:42 -0000	1.199
+++ modules/upload/upload.module	25 Feb 2008 03:19:04 -0000
@@ -579,60 +579,68 @@ function upload_load($node) {
  * Menu-callback for JavaScript-based uploads.
  */
 function upload_js() {
-  // Load the form from the Form API cache.
-  $cache = cache_get('form_'. $_POST['form_build_id'], 'cache_form');
-
-  // We only do the upload.module part of the node validation process.
-  $node = (object)$_POST;
-  unset($node->files['upload']);
-  $form = $cache->data;
-  $form_state = array('values' => $_POST);
-
-  // Handle new uploads, and merge tmp files into node-files.
-  upload_node_form_submit($form, $form_state);
-  $node_files = upload_load($node);
-  if (!empty($form_state['values']['files'])) {
-    foreach ($form_state['values']['files'] as $fid => $file) {
-      if (is_numeric($fid)) {
-        $node->files[$fid] = $file;
-        if (!isset($file['filepath'])) {
-          $node->files[$fid] = $node_files[$fid];
+  if (isset($_POST['form_build_id'])) {
+    // Load the form from the Form API cache.
+    $cache = cache_get('form_'. $_POST['form_build_id'], 'cache_form');
+  }
+  if (!empty($cache)) {
+    // We only do the upload.module part of the node validation process.
+    $node = (object)$_POST;
+    unset($node->files['upload']);
+    $form = $cache->data;
+    $form_state = array('values' => $_POST);
+  
+    // Handle new uploads, and merge tmp files into node-files.
+    upload_node_form_submit($form, $form_state);
+    $node_files = upload_load($node);
+    if (!empty($form_state['values']['files'])) {
+      foreach ($form_state['values']['files'] as $fid => $file) {
+        if (is_numeric($fid)) {
+          $node->files[$fid] = $file;
+          if (!isset($file['filepath'])) {
+            $node->files[$fid] = $node_files[$fid];
+          }
         }
       }
     }
-  }
-  $form = _upload_form($node);
-
-  // Update the default values changed in the $_POST array.
-  $files = isset($_POST['files']) ? $_POST['files'] : array();
-  foreach ($files as $fid => $file) {
-    if (is_numeric($fid)) {
-      $form['files'][$fid]['description']['#default_value'] = $file['description'];
-      $form['files'][$fid]['list']['#default_value'] = isset($file['list']) ? 1 : 0;
-      $form['files'][$fid]['remove']['#default_value'] = isset($file['remove']) ? 1 : 0;
-      $form['files'][$fid]['weight']['#default_value'] = $file['weight'];
+    $form = _upload_form($node);
+  
+    // Update the default values changed in the $_POST array.
+    $files = isset($_POST['files']) ? $_POST['files'] : array();
+    foreach ($files as $fid => $file) {
+      if (is_numeric($fid)) {
+        $form['files'][$fid]['description']['#default_value'] = $file['description'];
+        $form['files'][$fid]['list']['#default_value'] = isset($file['list']) ? 1 : 0;
+        $form['files'][$fid]['remove']['#default_value'] = isset($file['remove']) ? 1 : 0;
+        $form['files'][$fid]['weight']['#default_value'] = $file['weight'];
+      }
+    }
+  
+    // Add the new element to the stored form state and resave.
+    $cache->data['attachments']['wrapper'] = array_merge($cache->data['attachments']['wrapper'], $form);
+    cache_set('form_'. $_POST['form_build_id'], $cache->data, 'cache_form', $cache->expire);
+  
+    // Render the form for output.
+    $form += array(
+      '#post' => $_POST,
+      '#programmed' => FALSE,
+      '#tree' => FALSE,
+      '#parents' => array(),
+    );
+    drupal_alter('form', $form, array(), 'upload_js');
+    $form_state = array('submitted' => FALSE);
+    $form = form_builder('upload_js', $form, $form_state);
+    $output = theme('status_messages') . drupal_render($form);
+  
+    // We send the updated file attachments form.
+    // Don't call drupal_json(). ahah.js uses an iframe and
+    // the header output by drupal_json() causes problems in some browsers.
+    if ($output) {
+      print drupal_to_js(array('status' => TRUE, 'data' => $output));
+      exit();
     }
   }
-
-  // Add the new element to the stored form state and resave.
-  $cache->data['attachments']['wrapper'] = array_merge($cache->data['attachments']['wrapper'], $form);
-  cache_set('form_'. $_POST['form_build_id'], $cache->data, 'cache_form', $cache->expire);
-
-  // Render the form for output.
-  $form += array(
-    '#post' => $_POST,
-    '#programmed' => FALSE,
-    '#tree' => FALSE,
-    '#parents' => array(),
-  );
-  drupal_alter('form', $form, array(), 'upload_js');
-  $form_state = array('submitted' => FALSE);
-  $form = form_builder('upload_js', $form, $form_state);
-  $output = theme('status_messages') . drupal_render($form);
-
-  // We send the updated file attachments form.
-  // Don't call drupal_json(). ahah.js uses an iframe and
-  // the header output by drupal_json() causes problems in some browsers.
-  print drupal_to_js(array('status' => TRUE, 'data' => $output));
-  exit;
+  // We only get here if there was an error or invalid data in $_POST
+  drupal_json(array('status' => FALSE, 'data' => ''));
+  exit();
 }
