views:

60

answers:

1

I have a <?php print $search_box; ?> in my page.tpl.php page. On pages that exist, the search works, but on 404 pages, it does not.

I saw some bugs/patches threads over at drupal.org for D6.15, but none of them seem to work according to the thread and they weren't really relevant to D5.x

I have a theory that the because the <?php print $search_box; ?> creates a form with an action to itself(a non-existant page), it'll get the 404.

Has anyone run up against this? If so, how did you fix it?

One theory I has was to somehow tap into the form and always make the action="/" (front page) which would always exist.

If this is a good idea, how does one go about tapping into the FormAPI and overwriting the action? Is it a preprocess function?

+2  A: 
  1. In a form alter you can use drupal_get_headers() to check if the page being displayed is a 404.
  2. If it is a 404, you can in your form alter set the $form['#action'] attribute in your search form to fx the front page or any other page that you would like to redirect the user to.

I haven't tested this, but it should work.

googletorp
This got me in the right path. preprocess_page didn't have access to the $form, but I was able to search replace the action if the drupal_get_headers is a 404
easement