Tags:
create new tag
view all tags

SID-00363: How to include webs by checkboxes in search form

Status: Answered Answered TWiki version: 4.3.1 Perl version: 5.10.0
Category: CategorySearch Server OS: Windows XP Professional Last update: 16 years ago

The basic TWiki installation includes a search form which allows searching either the current web or all webs.

Is it possible to include a checkbox per web? This way, the user could narrow their search to just the webs checked.

-- DanKerr - 2009-06-11

Discussion and Answer

If I were coding this in another programming environment when the button was clicked, the parameter 'web' of SEARCH could be set by looping through each checkbox and adding it's value to the string if appropriate.

Is there a way to set a variable at the beginning of the page and then add to it when the user clicks "Search"?

-- DanKerr - 2009-06-11

Here are some hints on how I would approach this. It is possible to show a form with a checkbox per web. If you submit it you get multiple parameters such as item=Foo;item=Bar etc, e.g. not what we want. We need a single parameter such as web=Foo,Bar. You can achieve this by using some Javascript on focus loss of the checkboxes to populate a hidden input field named web.

Here is the first part, the form with dynamic checkbox list:

Blog
Codev
Main
Plugins
Sandbox
Support
TWiki
TWiki01
TWiki02
TWiki03
TWiki04
TWiki04x01
TWiki04x02
TWiki04x03
TWiki05x00
TWiki05x01
TWiki06x00
TWiki06x01
WikiWed

Now you need to add some Javascript to populate the hidden form field named "web".

For some additional inspiration study WebChangesForAllWebs.

-- PeterThoeny - 2009-06-13

Wow! Thanks for your guidance on this Peter, I'll post what I come up with.

-- DanKerr - 2009-06-15

Many thanks to PeterThoeny for the guidance on this issue. The code below is a search form including PT's checkbox weblist. It also includes a javascript function which loops through all the form's controls, checks for checkboxes and then adds their names to a variable which is then output as a hidden formfield called web.

It works great for us.

<script language="javascript" type="text/javascript">
   function loopForm(form) {
      var cbResults = '';
      for (var i = 0; i < form.elements.length; i++ ) {
         if (form.elements[i].type == 'checkbox') {
            if (form.elements[i].checked == true) {
               cbResults += form.elements[i].value + ', ';
            }
         }
      }
      // here we cut off the last ", "
      cbResults = cbResults.substring(0, cbResults.length-2)
      form.web.value = cbResults
   }
</script>

<form name="MySearchForm" action="%SCRIPTURL{view}%/Main/WebSearchResults">
   <p><strong>Search:</strong> <input type="text" class="twikiInputField" name="search" value="" size="50" /></p>
   <p><strong>Included webs:</strong> </p>
   <blockquote>
      %WEBLIST{ "<input type='checkbox' value='$name' /> $name<br />" }%
   </blockquote>
   <input type="hidden" name="type" value="keyword">
   <input type="hidden" name="scope" value="all">
   <input type="hidden" name="excludetopic" value="Web*">
   <input type="hidden" name="web">
   <input type="submit" class="twikiSubmit" value="Search" onclick="loopForm(document.MySearchForm);">
</form>

-- DanKerr - 2009-06-15

Thanks for reporting back Dan. I imagine this mod could be useful to other sites (me: I just forced it to always search all webs).

I took the liberty of reformatting your javascript in rev 5 because ... it needed it. smile

-- SeanCMorgan - 2009-06-16

Your welcome Dan. And thanks Sean for following up.

BTW, start tagging content, it helps people find useful stuff.

-- PeterThoeny - 2009-06-16

      Change status to:
ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
SupportForm
Status Answered
Title How to include webs by checkboxes in search form
SupportCategory CategorySearch
TWiki version 4.3.1
Server OS Windows XP Professional
Web server Apache 2.2.11
Perl version 5.10.0
Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r7 - 2009-06-16 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.