Restrict search to a minimum characters

Started by A.M.A, August 18, 2004, 11:49:23 AM

Previous topic - Next topic

A.M.A

open 'Search.template.php' and look for:
global $context, $settings, $options, $txt, $scripturl;

echo '
add after:
  <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>

You can change the number (3) to the minimum you need.
look for:
<form action="', $scripturl, '?action=search2" method="post" name="searchform" id="searchform">replace it with
<form onsubmit="return checkchars(this)" action="', $scripturl, '?action=search2" method="post" name="searchform" id="searchform">
Really sorry .. real life is demanding my full attention .. will be back soon hopefully :)

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.
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.
Really sorry .. real life is demanding my full attention .. will be back soon hopefully :)

Tomer

Quote from: A.M.A on August 18, 2004, 06:19:02 PM
That is for controlling the maximum length only ..

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 ..

Ohhh, what where you trying to do?
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" :)
Really sorry .. real life is demanding my full attention .. will be back soon hopefully :)

Tomer



Advertisement: