Coding Tips: February 2008 Archives
In a ProStores store, a blank keyword search will return "All" products — If you have a large catalog, this is never a good thing. Expecting your users to view 2000 items 25 items at a time is just silly. Here is a quick, easy way to completely remove the possibility of a blank keyword search in your ProStores store.
In Page Template Manager, locate the opening of the default keyword search form found in the Header template source code. It should look something like this:
<form method="post" action="$storeVersion.searchResults"></form>
There is a DOM event called "onSubmit". Using this event, we can easily add a test to the form that will keep the form from being submitted if the keyword input is empty. Example:
onSubmit="if(document.searchForm.keyword.value == '') return false;"
Once you correctly add the event to the form element it should look like this:
<form method="post" action="$storeVersion.searchResults" onSubmit="if(document.searchForm.keyword.value == '') return false;"></form>
Now, with no complicated form validation or any other scripting, your keyword search form cannot be submitted unless the user enters a keyword. That makes sense, right? You're welcome.
neoverve
Subscribe to the feed for this blog