Tags:
create new tag
view all tags

Question

Running into problems with using an HTML form to construct a search that will find which topics have which checkboxes checked on an attached form.

The background:

Imagine a TWiki form that is simply a number of checkboxes. And imagine many topics, all with that form attached.

By checking the appropriate boxes, a user can categorize a topic (when editing it).

Now, imagine that you want to search on those checkboxes. My idea was, use an HTML form to let the user check the desired boxes. Then, set a variable -- SEARCHVAR -- according to which boxes are checked, and use that variable to construct a search. The search should return whatever topics have (at least) the same boxes checked as the search form.

The details:

In my case, "ContentAreas" is the topic containing the table of checkbox names. I use a regex to pull the checkbox name out of that table. I use a search on that topic, with multiple="on", to build the series of checkboxes. So the code looks like:

<form action="%SCRIPTURLPATH%/view%SCRIPTSUFFIX%/%WEB%/%TOPIC%">

Content area(s):

%SEARCH{ topic="ContentAreas" search="| option |" nototal="on" noheader="on" multiple="on" format="<input type=\"checkbox\" name=\"q$pattern(\| ([^\|]+) \|.*)\" value=\"$pattern(\| (\w[^\|]+) \|.*)\"> $pattern(\| (\w[^\|]+) \|.*)$n" nosearch="on" }%

<!--
   * Set SEARCHVAR = %SEARCH{ topic="ContentAreas" search="| option |" nonoise="on" multiple="on" format="META:FIELD.*?ContentAreas.*?$percntURLPARAM{\"q$pattern(\| ([^\|]+) \|.*)\"}$percnt;" nofinalnewline="on"}%
-->
<!-- The preceding is NOT a comment.  It sets the search variable.  It just doesn't need to be visible on the wiki page. -->

<input type="submit" class="twikiSubmit" value="Search" />
</form>

|  *Results*  |||
%SEARCH{ search="%SEARCHVAR%" nonoise="on" type="regex" header="| Page  | Content Areas  | Summary  |" format="| [[$topic]]  | <nop>$formfield(ContentAreas)  | $summary  |" }%

The problem:

Can you see it coming? Say the user checked "Foo" and "Bar". We want to have SEARCHVAR equal to

      META:FIELD.*?ContentAreas.*?Foo;META:FIELD.*?ContentAreas.*?Bar

Instead, we have SEARCHVAR equal to

      META:FIELD.*?ContentAreas.*?Foo; META:FIELD.*?ContentAreas.*?Bar

See the extra space after the semicolon? It kills the search!

The question:

So, what workarounds are there?

  • Is there a way to modify the behavior of the SEARCH that I use in Set SEARCHVAR = so that it doesn't insert those spaces?
  • Or is there a way to strip spaces out of a given variable value?
  • Or is there some other way entirely of doing this search?

Thanks for any help!

Environment

TWiki version: TWikiRelease04x00x02
TWiki plugins: SpreadSheetPlugin, CalendarPlugin, CommentPlugin, EditTablePlugin, ImageGalleryPlugin, InterwikiPlugin, PreferencesPlugin, RedDotPlugin, RenderListPlugin, SlideShowPlugin, SmiliesPlugin, TablePlugin, WysiwygPlugin
Server OS: RHEL 4, kernel 2.6.9-22.0.2
Web server: Apache/2.0.52
Perl version: 5.8.5
Client OS: OS X 10.4.6
Web Browser: Firefox 1.5.0.3
Categories: Forms, Search

-- EaCohen - 18 May 2006

Answer

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.

Regarding the spaces in SEARCHVAR, have you tried including separator="" in the search?

-- LynnwoodBrown - 18 May 2006

That does it! Thanks. So, you think I should write this up in case anyone else wants to search using checkboxes?

-- EaCohen - 19 May 2006

Absolutely! I think there are a couple of different cases here that would be good candidates for SearchPatternCookbook. First, the search that creates the checkbox-formatted search form and second, the search results that use that form.

-- LynnwoodBrown - 19 May 2006

Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2006-05-19 - LynnwoodBrown
 
  • 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-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.