Hi,

Drupal themed 404 error pages may have a search field (for example http://drupal.org/foobar or something else on drupal.org that does not exist), however, that search field itself is not functional (you enter something, submit it, and are back on the page not found page). It would be nice if it could be made to work, because usually, when you get a 'page not found' error, the first thing you want to do is probably use the search function to find the correct page.

Regards
frostschutz

CommentFileSizeAuthor
#5 404_search_patch0.txt465 bytespwolanin
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

craines’s picture

We found this same problem when arriving at an error 403. I'm not sure as to the exact cause, but it appears to stem from the fact that the action parameter of the search block form defaults to the same url as the current page.

When you submit, the search module seems to intercept it and redirect you to the search results -- but this doesn't happen on a 404, 403, or on pages such as project/issues (my guess is that the project module intercepts it first -- you can try it out by using the search block at drupal.org/project/issues).

We fixed it by setting the $form['#action'] to 'search/node' (search.module drupal v4.7.2, lines 1041 & 1042 below). This seems to work fine on our site but not sure of the full ramifications of this change...

1026 : /**
1027 :  * Output a search form for the search block and the theme's search box.
1028 :  */
1029 : function search_box($form_id = 'search_theme_form') {
1030 :   // Use search_keys instead of keys to avoid ID conflicts with the search block.
1031 :   $form[$form_id .'_keys'] = array(
1032 :     '#type' => 'textfield',
1033 :     '#size' => 15,
1034 :     '#default_value' => '',
1035 :     '#attributes' => array('title' => t('Enter the terms you wish to search for.')),
1036 :   );
1037 :   if ($form_id == 'search_theme_form') {
1038 :     $form['#theme']['theme_search_theme_form'] = array();
1039 :   }
1040 :   $form['submit'] = array('#type' => 'submit', '#value' => t('Search'));
1041 :   // #### Fix issue with form action url ####
1042 :   $form['#action'] = url('search/node'); 
1043 : 
1044 :   return drupal_get_form($form_id, $form, 'search_box_form');
1045 : }
RobRoy’s picture

Priority: Minor » Normal

I think this is at least a 'normal' issue. Could we somehow check if we are on a 404/403 page and then change the action to search/node? Or, are there any issues with always having the action set to this?

rickvug’s picture

See the Search 404 module: http://drupal.org/node/26010 . This might be what you are looking for.

RobRoy’s picture

That looks like a nice module, but not the issue. When going to http://drupal.org/foobar and then trying a search from the search box, say for "Drupal". You don't get a list of search results as the action of that form is going to a non-existing page.

pwolanin’s picture

Status: Active » Needs review
FileSize
465 bytes

I'm seeing the same behavior on the 403 or 404 page- very non-intuitive.

The fix in #1 seems to work for me, and I don't see why it should cause any problems, given the submit function:

/**
 * Process a block search form submission.
 */
function search_box_form_submit($form_id, $form_values) {
  return 'search/node/'. trim($form_values[$form_id .'_keys']);
}

Attached as a patch against 4-7-CVS version of search.module.

beginner’s picture

Version: 4.7.2 » x.y.z
Status: Needs review » Reviewed & tested by the community

It's simple enough and it works (tested on cvs/head).

(I'm just a little confused at the way you create 4.7-cvs patches :) I had to manually enter the name of the file to patch -- maybe it's intended this way.)

pwolanin’s picture

Some of these patches are made just against a copy of the original file using "diff" on the command line (Mac OSX). They work fine for me with "patch -p0 < patchfile" on the command line. Most of my more recent patches have been made with "cvs diff" (now that I've sort of got the hang of cvs), and that produces a slightly different header- perhaps that's the difference.

drumm’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD with a modified comment.

pwolanin’s picture

Status: Fixed » Reviewed & tested by the community

commited to 4.7 branch?

drumm’s picture

Status: Reviewed & tested by the community » Fixed

No need to ask... killes will get to it.

killes@www.drop.org’s picture

Title: search field on 404 page not functional » search field on 404 page not functional

backported

Anonymous’s picture

Status: Fixed » Closed (fixed)
Scott’s picture

Version: x.y.z » 4.7.3
Status: Closed (fixed) » Reviewed & tested by the community

The current download of 4.7.3 does not include the patch for this bug in search.module

pwolanin’s picture

Status: Reviewed & tested by the community » Fixed

you are correct- the reason is that released versions are fixed. You can get the latest patched version of 4.7 at: http://drupal.org/drupal-4.7-cvs, otherwise this patch will be included when there is a 4.7.4 release.

Anonymous’s picture

Status: Fixed » Closed (fixed)