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.
I just discovered Custom Search, and it has solved many concerns I had for searches on a big site I'm creating.
But one issue I can't figure out is whether there is a setting to retain the user's search values on the search results page. To me, it seems logical to want to tailor a search after seeing the results, and having all the form fields be set would make that much easier for the user.
(I see these values in the URL arguments, but my users will not be sophisticated enough to modify those by hand.)
Thanks for any advice!
Comment | File | Size | Author |
---|---|---|---|
#9 | custom_search-preserve-search-query-2065737-9-D7.patch | 2.01 KB | benjaminbradley |
#7 | custom search request.jpg | 34.78 KB | garamani |
#1 | test-search.png | 14.32 KB | jdanthinne |
Comments
Comment #1
jdanthinne CreditAttribution: jdanthinne commentedHi,
what do you mean by "having all the form fields be set"? Which form? Which fields?
By default, the search field in the results page already contains the searched keyword.
Ie: the result page when I search "test"…
Comment #2
senortim CreditAttribution: senortim commentedHi, thanks. That's actually not the case for my search page. If I put "test" in my search field (either provided by the Search block, or on the Search results page itself), then click submit, the new results page's search box has Custom Search's default text (which in my case is "search").
So that's one issue. But the other is that I have lots of other search filters -- content types, taxonomies, and so on -- and it would be ideal if these *remembered* the previous submitted search.
Considering that this is pretty standard behavior, I feel like Custom Search probably does this, but if so, it isn't working at all for me.
(FWIW, on HTML pages I've built before Drupal, I checked $_POST values and then configured select options with those values, thus remembering the previous submission.)
Comment #3
jdanthinne CreditAttribution: jdanthinne commentedSo what you want is to re-select the choices you've made for the initial search in the Search block (in the sidebar, or header, let's say), not the Search form in the results page (in the main content)?
In this case, it's a feature to implement, not a bug…
Comment #4
senortim CreditAttribution: senortim commentedThanks for your reply. I've changed the status to feature request. And considering that I probably need this for my project, I'll see whether I can contribute those changes.
Comment #5
garamani CreditAttribution: garamani commented@ jdanthinne: Please consider this Feature as a serious Request.
Having the Search inputs (keywords, content type selection) after submitting the search form, help users to refine the search results better.
Comment #6
jdanthinne CreditAttribution: jdanthinne commentedEvery new request is considered serious, but I'm very busy at my daily job, and the free time I have for this module is used for the D8 transition.
New co-maintainers are welcome, patches as well.
Comment #7
garamani CreditAttribution: garamani commentedThanks for your quick and honest answer.
I understand that what you are doing for this module is personal passion more than anything. Actually this module fills a huge gap that Drupal doesn't offer out of the box. Having a custom search form and custom search results is the most important part of website.
Custom search module + Display suite module brings an acceptable customized search functionality.
So, if it's possible for you, please give this particular feature request a higher priority.
I need to accomplish something like this (using custom search selectors):
Comment #8
garamani CreditAttribution: garamani commented@ senortim: Have you found any solution, patch, ... ?
Comment #9
benjaminbradley CreditAttribution: benjaminbradley commentedI implemented this by adding a new configuration checkbox "Override search box text with current search query" just under the current Search Box Text configuration. If this is checked, and the current search query is not blank, it will be used as the default value of the search query textfield.
I wasn't sure of the best way to get the current search keyword value, so I'm just pulling it from arg(2) (as in /search/node/[keywords]). Let me know if there's a better way to do that.
Comment #10
Stolzenhain CreditAttribution: Stolzenhain commentedI'm not sure about the exact dangers, but injecting arguments straight into code usually has security implications; you should at least escape
arg(2)
, I guess.For the record: I was struggling with the same problem and realized it via Javascript injection, which is way more hacky, but also a bit more secure.