Customizing SMF > SMF Coding Discussion
Restrict search to a minimum characters
A.M.A:
open 'Search.template.php' and look for:
--- Code: --- global $context, $settings, $options, $txt, $scripturl;
echo '
--- End code ---
add after:
--- Code: --- <script LANGUAGE="JavaScript"><!--
function checkchars(form) {
var max=3;
if (form.search.value.length < max) {
alert("Minimum allowed characters is (" + max + "). Please try again.");
return false;
}
else return true;
}
// --></script>
--- End code ---
You can change the number (3) to the minimum you need.
look for:
--- Code: ---<form action="', $scripturl, '?action=search2" method="post" name="searchform" id="searchform">
--- End code ---
replace it with
--- Code: ---<form onsubmit="return checkchars(this)" action="', $scripturl, '?action=search2" method="post" name="searchform" id="searchform">
--- End code ---
Tomer:
I strongly suggest not using JS!
Just add maxlength='3' to the search form. Much easier.
A.M.A:
--- Quote from: Tomer Dean on August 18, 2004, 12:05:24 PM ---I strongly suggest not using JS!
Just add maxlength='3' to the search form. Much easier.
--- End quote ---
That is for controlling the maximum length only .. i.e. you can't enter more than 3 characters .. there is another way of controlling minimum length but it requires the FrontPage extension.
Tomer:
--- Quote from: A.M.A on August 18, 2004, 06:19:02 PM ---That is for controlling the maximum length only ..
--- End quote ---
Ohhh, what where you trying to do?
A.M.A:
--- Quote from: Tomer Dean on August 18, 2004, 06:24:20 PM ---
--- Quote from: A.M.A on August 18, 2004, 06:19:02 PM ---That is for controlling the maximum length only ..
--- End quote ---
Ohhh, what where you trying to do?
--- End quote ---
If you applied my code above .. any one who tries to search for .. let say "xp" or "m" will end up with the alert message that he can't do search! but if he searches for "xp1" or "mmm" or "xpmmm" the search will commence
now you may say what the heck is that for!! Will let say you have 100.000 posts and some one tries to search for just one letter! or try it here and search for only "i" :)
Navigation
[0] Message Index
[#] Next page
Go to full version