Index: modules/search/search.pages.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/search/search.pages.inc,v
retrieving revision 1.19
diff -u -r1.19 search.pages.inc
--- modules/search/search.pages.inc	1 May 2010 01:04:24 -0000	1.19
+++ modules/search/search.pages.inc	11 Jun 2010 19:58:50 -0000
@@ -10,40 +10,39 @@
  * Menu callback; presents the search form and/or search results.
  */
 function search_view($type = 'node') {
-  // Search form submits with POST but redirects to GET. This way we can keep
-  // the search query URL clean as a whistle:
-  // search/type/keyword+keyword
-  if (!isset($_POST['form_id'])) {
-    $keys = search_get_keys();
-    if ($_GET['q'] != 'search' && $type == 'node' && !$keys) {
-      // Due to how search_menu() sets up the tabs, path search/node would
-      // display two sets of tabs. So instead, if there are no keywords and
-      // we're on the node tab, just redirect to the bare 'search' path.
-      drupal_goto('search');
-    }
-
-    // Only perform search if there is non-whitespace search term:
-    $results = '';
-    if (trim($keys)) {
-      // Log the search keys.
-      $info = search_get_info();
-      watchdog('search', 'Searched %type for %keys.', array('%keys' => $keys, '%type' => $info[$type]['title']), WATCHDOG_NOTICE, l(t('results'), 'search/' . $type . '/' . $keys));
-
-      // Collect the search results.
-      $results = search_data($keys, $type);
-
-      // Construct the search form.
-      $build['search_form'] = drupal_get_form('search_form', NULL, $keys, $type);
-      $build['search_results'] = array(
-        '#theme' => 'search_results_listing',
-        '#content' => $results,
-      );
+  // Process the search form.
+  $keys = search_get_keys();
+  $form = drupal_get_form('search_form', NULL, $keys, $type);
+
+  if ($_GET['q'] != 'search' && $type == 'node' && !$keys) {
+    // Due to how search_menu() sets up the tabs, path search/node would
+    // display two sets of tabs. So instead, if there are no keywords and
+    // we're on the node tab, just redirect to the bare 'search' path.
+    drupal_goto('search');
+  }
+
+  // Only perform search if there is non-whitespace search term.
+  $results = '';
+  if (trim($keys)) {
+    // Log the search keys.
+    $info = search_get_info();
+    watchdog('search', 'Searched %type for %keys.', array('%keys' => $keys, '%type' => $info[$type]['title']), WATCHDOG_NOTICE, l(t('results'), 'search/' . $type . '/' . $keys));
+
+    // Collect the search results.
+    $results = search_data($keys, $type);
+
+    // Construct the search form.
+    $build['search_form'] = $form;
+    $build['search_results'] = array(
+      '#theme' => 'search_results_listing',
+      '#content' => $results,
+    );
 
-      return $build;
-    }
+    return $build;
   }
 
-  return drupal_get_form('search_form', NULL, empty($keys) ? '' : $keys, $type);
+  // If there were no keys, just display the search form.
+  return $form;
 }
 
 /**
Index: modules/search/search.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/search/search.test,v
retrieving revision 1.64
diff -u -r1.64 search.test
--- modules/search/search.test	8 Jun 2010 06:34:36 -0000	1.64
+++ modules/search/search.test	11 Jun 2010 19:58:50 -0000
@@ -1169,3 +1169,79 @@
     return '';
   }
 }
+
+/**
+ * Tests that we can embed a form in search results and submit it.
+ */
+class SearchEmbedForm extends DrupalWebTestCase {
+  /**
+   * Node used for testing.
+   */
+  public $node;
+
+  /**
+   * Count of how many times the form has been submitted.
+   */
+  public $submit_count = 0;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Embedded forms',
+      'description' => 'Verifies that a form embedded in search results works',
+      'group' => 'Search',
+    );
+  }
+
+  function setUp() {
+    parent::setUp('search', 'search_embed_form');
+
+    // Create a user and a node, and update the search index.
+    $test_user = $this->drupalCreateUser(array('access content', 'search content', 'administer nodes'));
+    $this->drupalLogin($test_user);
+
+    $this->node = $this->drupalCreateNode();
+
+    node_update_index();
+    search_update_totals();
+
+    // Set up a dummy initial count of times the form has been submitted.
+    $this->submit_count = 12;
+    variable_set('search_embed_form_submitted', $this->submit_count);
+    $this->refreshVariables();
+  }
+
+  /**
+   * Tests that the embedded form appears and can be submitted.
+   */
+  function testEmbeddedForm() {
+    // First verify we can submit the form from the module's page.
+    $this->drupalPost('search_embed_form',
+      array('name' => 'John'),
+      t('Send away'));
+    $this->assertText(t('Test form was submitted'), 'Form message appears');
+    $count = variable_get('search_embed_form_submitted', 0);
+    $this->assertEqual($this->submit_count + 1, $count, 'Form submission count is correct');
+    $this->submit_count = $count;
+
+    // Now verify that we can see and submit the form from the search results.
+    $this->drupalGet('search/node/' . $this->node->title);
+    $this->assertText(t('Your name'), 'Form is visible');
+    $this->drupalPost('search/node/' . $this->node->title,
+      array('name' => 'John'),
+      t('Send away'));
+    $this->assertText(t('Test form was submitted'), 'Form message appears');
+    $count = variable_get('search_embed_form_submitted', 0);
+    $this->assertEqual($this->submit_count + 1, $count, 'Form submission count is correct');
+    $this->submit_count = $count;
+
+    // Now verify that if we submit the search form, it doesn't count as
+    // our form being submitted.
+    $this->drupalPost('search',
+      array('keys' => 'foo'),
+      t('Search'));
+    $this->assertNoText(t('Test form was submitted'), 'Form message does not appear');
+    $count = variable_get('search_embed_form_submitted', 0);
+    $this->assertEqual($this->submit_count, $count, 'Form submission count is correct');
+    $this->submit_count = $count;
+  }
+}
\ No newline at end of file
Index: modules/search/tests/search_embed_form.module
===================================================================
RCS file: modules/search/tests/search_embed_form.module
diff -N modules/search/tests/search_embed_form.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/search/tests/search_embed_form.module	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,66 @@
+<?php
+// $Id: $
+
+/**
+ * @file
+ * Test module implementing a form that can be embedded in search results.
+ */
+
+/**
+  * Implements hook_menu().
+  */
+function search_embed_form_menu() {
+  $items['search_embed_form'] = array(
+    'title' => 'Search_Embed_Form',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('search_embed_form_form'),
+    'access arguments' => array('search content'),
+    'type' => MENU_CALLBACK,
+  );
+
+  return $items;
+}
+
+/**
+ * Builds a form for embedding in search results for testing.
+ *
+ * @see search_embed_form_form_submit().
+ */
+function search_embed_form_form($form, &$form_state) {
+  $count = variable_get('search_embed_form_submitted', 0);
+
+  $form['name'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Your name'),
+    '#maxlength' => 255,
+    '#default_value' => '',
+    '#required' => TRUE,
+    '#description' => t('Times form has been submitted: %count', array('%count' => $count)),
+  );
+
+  $form['actions'] = array('#type' => 'actions');
+  $form['actions']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Send away'),
+  );
+
+  $form['#submit'][] = 'search_embed_form_form_submit';
+
+  return $form;
+}
+
+/**
+ * Submit handler for search_embed_form_form().
+ */
+function search_embed_form_form_submit($form, &$form_state) {
+  $count = variable_get('search_embed_form_submitted', 0) + 1;
+  variable_set('search_embed_form_submitted', $count);
+  drupal_set_message(t('Test form was submitted'));
+}
+
+/**
+ * Adds the test form to search results.
+ */
+function search_embed_form_preprocess_search_result(&$variables) {
+  $variables['snippet'] .= drupal_render(drupal_get_form('search_embed_form_form'));
+}
Index: modules/search/tests/search_embed_form.info
===================================================================
RCS file: modules/search/tests/search_embed_form.info
diff -N modules/search/tests/search_embed_form.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/search/tests/search_embed_form.info	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,8 @@
+; $Id: $
+name = "Test extra form"
+description = "Support module for search module testing."
+package = Testing
+version = VERSION
+core = 7.x
+files[] = search_embed_form.module
+hidden = TRUE
