Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By chunty on
Does anyone know how to remove the search form from the search results page. NOTE: I'm not talking about the search block but the form that gets stuck at the top of the list of results.
I've tried the stuff here http://drupal.org/node/45295 and cleared my cache like there's no tomorrow, but I think that the form on the results page might not use "search_theme_form" because I've even tried modifying "modules/search/search-theme-form.tpl.php" directly and it had no effect.
Any got any bright ideas?
Chris
Comments
Hmm, thats a tricky one
Hmm, thats a tricky one because the function is the same for building both the initial search page and the search results page - so if you want the form to appear on the original page but not results, its going to be difficult. You could use jquery and css to hide the form on a results page using display:none, or copy the search module into your sites module directory and adapt it to your purposes.
When you say the original page, what do you mean.
I'm using the search block in the header to submit my initial request to http://sitename.com/search (if that makes sense), basically when I arrive on the page after I've submitted a search from the search block I don't ever want a search form - there's no point having 2 forms on the page (I keep the search block in the header even when I'm on the search results page) and its looks a bit ugly and pushes everything down the page
If that makes sense? - does that make life easier?
C
Definitely. Target it using
Definitely. Target it using CSS and give it a display:none setting.
For example, on a zen subtheme it might look like:
div#content form#search-form {display:none;}
You'll want to find a rule specific enough to target only the search form in the main section of your site, not the form in the block.
..and without CSS
Is there any way to do this with a hook function or template file, whilst techinically there's nothing wrong with the CSS route it always feels a bit hacky to me.
C
You could use hook_form_alter
You could use hook_form_alter and remove all the visible elements. Or copy the search module to your sites module directory and remove "$output = drupal_get_form('search_form', NULL, $keys, $type);" from the page callback in search.pages.inc. This last way is "hacking core", so while its cleaner and lighter code wise, its probably not the most drupal kosher way to go.
maybe a solution
If it can help someone, i found a solution a bit dirty but still better than hidding with CSS or hacking core.
here is my code :
Of course, you have to change theme_form by NameOfYourTheme_form.
Hope it will help someone.
have you solved this issue?
have you solved this issue? will you please share how?
subscribing
subscribing
The problem with all the
The problem with all the solutions presented here is that, if you want a persistent search form in your header then there's no way to consistently distinguish it from the form that gets generated on the search results page. The results page gets rendered first, so the form gets the id "search-form" and the form in the header becomes "search-form-1". Otherwise, the header becomes "search-form". So which one do you hide via CSS? Or hook_form_alter for that matter? This is one of those problems that I would expect to see more people complaining about. It would be nice if the Search module separated the form from the results. On sites I've done in the past I've simply left the form on the results page. there didn't seem to be any other way of dealing with it. I would love to be proven wrong, though.
I've been fighting with this
I've been fighting with this for two days now. In Drupal 7 I completely remove the form with hook_preprocess_page() or hook_page_alter() and it still shows up! There has to be a way...
Finally figured out why
Finally figured out why removing the form via hook_page_alter() was not working. For some crazy reason the $page array is different depending on whether you are logged in or not. So when I looked at $page using Devel dsm() (logged in) and unset the form there, it was still appearing in the other browser (not logged in).
Remove search form on the results page (D7):
Thank you!
Thank you!
thanks a lot , happy to find
thanks a lot , happy to find the solution here
Dev Server Shared Hosting
8 websites powered by drupal 6,8 & 9 - Hosted by Always Data
does this work with D6?
does this work with D6?
The following code worked for
The following code worked for me on Drupal 6:
Some hidden fields are left in the code, so the entire form is not removed, but your visitors won't see the search form...
thank you!
that helped a LOT.
:)
Thanks @progpapa and just to
Thanks @progpapa and just to clarify this would need to be put in your own module and replace "modulename" with the name of your new module see http://drupal.org/node/206754.
Thanks
Yes, to clarify this modules works great. However is there a possibly way to add to it to also remove the title/header 'Search', and the below options for catagories to search (mine has 3 buttons: help, users, content)?
page.tpl.php
You can remove rest of the search elements within your page.tpl.php.
e.g.
I'm using for my condition:
Thx a lot!
Thx a lot!
A different solution
And I'm facing the same problem again, now I'm using a different solution:
It works if you are searching for nodes.
Something like
should work too.
It seems to be more elegant and leaves no code in the source.
Slight varation on this (D7)
To keep the search form on the search page, but remove it on search results page, I used a slight variation on the solution above:
I was working only with nodes, but a more generic conditional would also work. The important part is testing arg(2), which is NULL on the search page, but non-null on search result pages.
Great help
This method worked perfectly for me, thank you.
you're the man
you're the man
This worked for me (Drupal 7)
Hi, just got into Drupal about 2 weeks ago with a big project and lots of challenges. Loving Drupal by the way.
This hook worked for me:
NOTE: replace [mytheme] with your theme name
While rendering content , you
While rendering content , you can unset search form like this
Is it okay