This topic is locked

Basic Search text box

9/2/2005 3:40:30 PM
PHPRunner General questions
M
Mona author

Can the Basic Search text box (or the Advanced Search box for that matter) be modified such that the user must enter a predetermined number of characters in order to result in a successful match? For example, when searching on company name "ACME Manufacturing" the users must enter at least 7 characters "ACME MA" in order to get a match?
If this is not possible, are there ANY other ways to restrict the text box field? Or perhaps limit the options within the Advanced Search function (e.g. exact match only)?

Admin 9/6/2005

Mona,
you can use Javascript to deny users entering short search strings.

Here are modifications you can make in your ..._list.php file

  1. Find this snippet in your ..._list.file

<!-- Search form -->

<form name="frmSearch" method="GET" action="..._list.php">

and replace it with

<!-- Search form -->

<script language=Javascript>

function CheckSearchStr()

{

if(frmSearch.SearchOption.value=='Empty')

 return true;

if(frmSearch.SearchFor.value.length>=7)

return true;

alert('Search phrase must be 7 or more chars length.');

return false;

}

</script>

<form name="frmSearch" method="GET" action="..._list.php" onsubmit="return CheckSearchStr()">



Don't forget to replace ..._list.php with your actual filename.
2. Then find this:

<input type=button class=button name="SearchButton" value="Search"

onClick="javascript: document.forms.frmSearch.a.value = 'search';

document.forms.frmSearch.submit();">



and replace with:

<input type=button class=button name="SearchButton" value="Search"

onClick="javascript: document.forms.frmSearch.a.value = 'search';

if(CheckSearchStr()) document.forms.frmSearch.submit();">