summaryrefslogtreecommitdiff
path: root/modules/search
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-12-06 07:00:30 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-12-06 07:00:30 +0000
commit363256d009bbca4adc5cec0a9a57c47b60c69a1b (patch)
treeb38807be6a02bed9b42014db8356023fd0c87852 /modules/search
parent2c77be1b606bebf638a5b9b9db5914cd68199cc0 (diff)
downloadbrdo-363256d009bbca4adc5cec0a9a57c47b60c69a1b.tar.gz
brdo-363256d009bbca4adc5cec0a9a57c47b60c69a1b.tar.bz2
#518512 by lelutin, dwong127, jhodgdon, nadavoid: Fixed Search from block with no keywords doesn't display the 'Please enter some keywords' message
Diffstat (limited to 'modules/search')
-rw-r--r--modules/search/search.module10
-rw-r--r--modules/search/search.test19
2 files changed, 29 insertions, 0 deletions
diff --git a/modules/search/search.module b/modules/search/search.module
index 1f4238797..027643485 100644
--- a/modules/search/search.module
+++ b/modules/search/search.module
@@ -1036,6 +1036,16 @@ function search_box_form_submit($form, &$form_state) {
unset($_GET['destination']);
}
+ // Check to see if the form was submitted empty.
+ // If it is empty, display an error message.
+ // (This method is used instead of setting #required to TRUE for this field
+ // because that results in a confusing error message. It would say a plain
+ // "field is required" because the search keywords field has no title.
+ // The error message would also complain about a missing #title field.)
+ if ($form_state['values']['search_block_form'] == '') {
+ form_set_error('keys', t('Please enter some keywords.'));
+ }
+
$form_id = $form['form_id']['#value'];
$info = search_get_default_module_info();
if ($info) {
diff --git a/modules/search/search.test b/modules/search/search.test
index d5aacda92..fa5278c44 100644
--- a/modules/search/search.test
+++ b/modules/search/search.test
@@ -617,6 +617,25 @@ class SearchBlockTestCase extends DrupalWebTestCase {
$this->drupalPost('admin/structure/block/manage/search/form/configure', $edit, t('Save block'));
$this->drupalPost('node', $terms, t('Search'));
$this->assertText('Your search yielded no results');
+
+ // Confirm that the user is redirected to the search page.
+ $this->assertEqual(
+ $this->getUrl(),
+ url('search/node/' . $terms['search_block_form'], array('absolute' => TRUE)),
+ t('Redirected to correct url.')
+ );
+
+ // Test an empty search via the block form, from the front page.
+ $terms = array('search_block_form' => '');
+ $this->drupalPost('node', $terms, t('Search'));
+ $this->assertText('Please enter some keywords');
+
+ // Confirm that the user is redirected to the search page, when form is submitted empty.
+ $this->assertEqual(
+ $this->getUrl(),
+ url('search/node/', array('absolute' => TRUE)),
+ t('Redirected to correct url.')
+ );
}
}