SID-01034: Form Field Search Behaving Oddly with URLPARAM query
| Status: |
Answered |
TWiki version: |
5.0.1 |
Perl version: |
|
| Category: |
CategorySearch |
Server OS: |
|
Last update: |
15 years ago |
Hi,
I'm using TWiki to teach a class in online information system design, and I'm trying to build a demo application that would enable users to browse a collection of a topics based on a list of parameters drawn from a form field. For this application, the topics are all recipes, and there is a form field called RecipeType, where recipes are categorized by type, such as Appetizer, Entree, etc, in a form called RecipePrototypeForm. In the code below, the first %CALC creates a subcat_list variable by getting the selected types from the RecipeType field. The second %CALC formats the results as a linked list, where the, when the user clicks on the link, that type gets passed as a URLPARAM, which in turn is passed to the =%SEARCH variable. As hacky as it may seem, this works perfectly, and if you click on the Appetizer link, for example, you see only those topics that have Appetizer selected in the RecipeType field.
However, there is a wonky problem. When the page first loads, before you click on any of the links, the %SEARCH functions such that it retrieves a list of all topics that
don't have the RecipePrototypeForm attached to them (and none of the ones that do). I expect that this has something to do with the RecipeType value being "empty" when the page first loads, but I'm flummoxed on how to fix this. I built another version of this several years ago using RegEx and it worked great, but would really prefer to use the much simplified query seach.
<ul>
%CALC{$SET(subcat_list,$LISTSORT(%SEARCH{"RecipeTypeList" scope="topic" nototal="on" noheader="on" nosearch="on" casesensitive="on" format="$formfield(RecipeType)"}%))}%
%CALC{$TRANSLATE($LISTMAP(<li>[[%SCRIPTURL%/view/PRWR637Course/BuildaSubjectBrowser?Type=$NOP(%)INTURLENCODE{$item}$NOP(%)][$item]], $GET(subcat_list)),$comma, )}%
</ul>
|*Recipe Type*|*Recipe Title*|
%SEARCH{ type="query" "RecipePrototypeForm.RecipeType='%URLPARAM{"Type"}%'" web="PRWR637Course" excludetopic="RecipePrototypeForm, RecipeTypeList" nonoise="on" format=" | $formfield(RecipeType) | [[$topic][$formfield(Title)]] |" }%
This isn't behind a firewall, so you can see the actual functioning demo here:
http://cla-techcom.towson.edu/twiki/bin/view/PRWR637Course/BuildaSubjectBrowser
Note that it isn't finished being written, but the demo app is at the bottom of the page.
--
PhilGochenour - 2010-11-23
Discussion and Answer
As usual, it only took a break, some food, and I figured out the problem - I decided to switch to a regex solution, as follows:
<ul>
%CALC{$SET(subcat_list,$LISTSORT(%SEARCH{"RecipeTypeList" scope="topic" nototal="on" noheader="on" nosearch="on" casesensitive="on" format="$formfield(RecipeType)"}%))}%
%CALC{$TRANSLATE($LISTMAP(<li>[[%SCRIPTURL%/view/PRWR637Course/BuildaSubjectBrowser?Type=$NOP(%)URLENCODE{$item}$NOP(%)][$item]], $GET(subcat_list)),$comma, )}%
</ul>
|*Recipe Type*|*Recipe Title*|
%SEARCH{ type="regex" "[R]ecipeTitle.*?value=.*?[a-zA-Z];RecipeType.*?value=.*?(%URLPARAM{"Type"}%)" web="PRWR637Course" excludetopic="RecipePrototypeForm, RecipeTypeList" nonoise="on" format=" | $formfield(RecipeType) | [[$topic][$formfield(RecipeTitle)]] |" }%
--
PhilGochenour - 2010-11-24
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.