Right now if I don't enter a search query in the drupal search module, it returns results for 'search'. I would like it to display an error prompting the user to enter a search query instead. Is there some sort of setting?

  • If the search term doesn't contain at least three characters, the Search module should already report an error message.
    – apaderno
    Commented Apr 18, 2011 at 17:07
  • but if i don't enter anything it searches for search
    – Linens
    Commented Apr 18, 2011 at 17:52

2 Answers 2


The form submission callback for the search form is the following function.

function search_form_submit($form, &$form_state) {
  $keys = $form_state['values']['processed_keys'];
  if ($keys == '') {
    form_set_error('keys', t('Please enter some keywords.'));
    // Fall through to the drupal_goto() call.

  $type = $form_state['values']['module'] ? $form_state['values']['module'] : 'node';
  $form_state['redirect'] = 'search/' . $type . '/' . $keys;

If, when you don't enter anything, Drupal searches for search, there must be a module that alter the content of $form_state['values']['processed_keys'] when it is an empty string.

  • I don't think so.. could it possibly be the theme?
    – Linens
    Commented Apr 18, 2011 at 19:23
  • @Ima Student Themes are not supposed to change the search string, and a theme doesn't usually implement hook_form_alter().
    – apaderno
    Commented Apr 18, 2011 at 19:31
  • I found it. It was actually in one of the include files in my theme // Set a default value for the search box $vars['form']['search_theme_form']['#value'] = t('Search...'); thanks for helping me get started on where to look though!
    – Linens
    Commented Apr 18, 2011 at 19:59

I know it's lazy, but I would do it with javascript. You'd save the extra wait time, and the load on your site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.