I would like to enclose a search term with Double quotes automatically
For e.g.
<input type="text" name="keywords" value="" id="search" size="17" />
<input type="submit" value="Go">
a visitor tries to search for a phrase = long enough (it contains 2 words with a space in between)
I need the string long enough to be passed as "long enough" to server side (PHP)
I dont want to tell the visitor to use Double quotes for searching for a phrase, for the visitor the search should be easy.
Presently, when a visitor enters a search term with one word long the search results show correct articles.
But when a visitor uses a phrase long enough or any other phrase, using a minimum of 2 words, the search results are not accurate as the search take long enough as 2 seperate search terms.
For accurate search results, the ExpressionEngine CMS wants the visitor to enter "long enough" [any phrase to be enclosed in double quotes]
This is what i want to do automatically, when a visitor searches for one word, it should leave the keyword and let it pass without any quotes, but when a visitor uses 2 or more words, the search form should pass those phrases in Double quotes
Code provided by @Jonathon Wisnoski works as i want it, but with one drawback
<script type="text/javascript">
function quoteWords() {
var search = document.getElementById("search_box");
search.value = search.value.replace(/^\s*|\s*$/g, ""); //trim string of ending and beginning whitespace
if(search.value.indexOf(" ") != -1){ //if more then one word
search.value = search.value.replace(/^"*|"*$/g, "\"");
}
}
</script>
Issue : It breaks when manually adding double quotes and pressing submit, one extra double quote is entered at the end. The regex code should see if the double quotes exist, it should not add any thing.
So it makes "long enough" to "long enough""
Can anyone check the regex code so see how to solve this issue.
long enoughshould appear on the server as a single string. If you really want to wrap that single string in double quotes, so that the quotes are part of the string, just add them to the front and back. Unless I am mis-understanding your question?