You are here:  » Empty search message


Empty search message

Submitted by pgabriel on Wed, 2007-01-10 16:21 in

Hello,

If anyone just clicks the search button and it has nothing in search field i would like to give him a message (i.e."Please wrote something there")

Can somebody help?

Thanks,
Gabriel

Submitted by support on Wed, 2007-01-10 16:33

Hello Gabriel,

This is best done with JavaScript on your search form. Try the following code to replace html/searchform.php:

<div class='searchform'>
  <form name='search' action='<?php print $config_baseHREF ?>search.php'>
    <input type='text' id='q' name='q' size='35' value='<?php print (isset($q)?$q:""); ?>' />
    <input type='submit' onclick='if (!document.search.q.value) {alert("Please enter a search term");return false;}' value='<?php print translate("Search"); ?>' />
  </form>
</div>

The only changes are the addition of the id attribute to the text box, and the javascript within the onclick attribute of the submit button. Don't forget to copy both changes through to your new search form in your advancedsearch.php if you want to do the same thing there...

Cheers,
David.