Advertisement:

Author Topic: Restrict search to a minimum characters  (Read 8989 times)

Offline A.M.A

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,133
  • Gender: Male
  • ..
Restrict search to a minimum characters
« on: August 18, 2004, 11:49:23 AM »
open 'Search.template.php' and look for:
Code: [Select]
global $context, $settings, $options, $txt, $scripturl;

echo '
add after:
Code: [Select]
  <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:
Code: [Select]
<form action="', $scripturl, '?action=search2" method="post" name="searchform" id="searchform">replace it with
Code: [Select]
<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 :)

Offline Tomer

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,652
  • Gender: Male
    • Aromazing
Re: Restrict search to a minimum characters
« Reply #1 on: August 18, 2004, 12:05:24 PM »
I strongly suggest not using JS!

Just add maxlength='3' to the search form. Much easier.

Offline A.M.A

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,133
  • Gender: Male
  • ..
Re: Restrict search to a minimum characters
« Reply #2 on: August 18, 2004, 06:19:02 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 :)

Offline Tomer

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,652
  • Gender: Male
    • Aromazing
Re: Restrict search to a minimum characters
« Reply #3 on: August 18, 2004, 06:24:20 PM »
That is for controlling the maximum length only ..

Ohhh, what where you trying to do?

Offline A.M.A

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,133
  • Gender: Male
  • ..
Re: Restrict search to a minimum characters
« Reply #4 on: August 18, 2004, 06:38:53 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 :)

Offline Tomer

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,652
  • Gender: Male
    • Aromazing
Re: Restrict search to a minimum characters
« Reply #5 on: August 18, 2004, 08:41:35 PM »
Hmmm ok, but its easier to just use PHP.

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male