From 363256d009bbca4adc5cec0a9a57c47b60c69a1b Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Mon, 6 Dec 2010 07:00:30 +0000 Subject: #518512 by lelutin, dwong127, jhodgdon, nadavoid: Fixed Search from block with no keywords doesn't display the 'Please enter some keywords' message --- modules/search/search.module | 10 ++++++++++ modules/search/search.test | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'modules/search') 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.') + ); } } -- cgit v1.2.3