ZenphotoCMS Forum
clear the search field if no results found - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: General support (https://forum.zenphoto.org/forum-4.html)
+--- Thread: clear the search field if no results found (/thread-8266.html)



clear the search field if no results found - flu - 2011-02-17

Hi,
when using search and nothing is found, wouldn't it be nice to clear the search field ?

Anyway, is there any trick to clear the search field in any case ?

Cheers !




clear the search field if no results found - sbillard - 2011-02-17

There should be a reset button to clear the field. Or do you mean programatic trick?




clear the search field if no results found - flu - 2011-02-17

That's it, I mean programatic trick.
Anyway - IMHO - I thought that my first request (if no result found) would get sense.

Cheers !




clear the search field if no results found - sbillard - 2011-02-17

$_zp_current_search->setSearchParams('words=');

This has to be done in the theme itself as the theme is the only entity that knows if the search was empty. We can add that to the standard themes.




clear the search field if no results found - flu - 2011-02-17

Thank you Stephen, I'll try it.




clear the search field if no results found - flu - 2011-02-18

Stephen,
could you please tell me where to write it in search.php ?
I'm a bit lost.

Cheers.




clear the search field if no results found - sbillard - 2011-02-18

First, turns out that is not sufficient. (The search engine caches the search!)

So what you need to do is place the following code in search.php somewhere before the call on printSearchForm()

$_zp_current_search->processed_search = ''; $_zp_current_search->words = '';
Of course, do this only if there have your page determines there are no results.




clear the search field if no results found - flu - 2011-02-20

That works.
A big thank you, Stephen !

Cheers !




clear the search field if no results found - sbillard - 2011-02-20

This will become a feature next release for distributed themes. There will be an object method to clear the search parameters.