r2 - 23 Jul 2004 - 07:22:55 - PeterThoenyYou are here: TWiki >  Codev Web > FormattedSearchUsesTitleInsteadOfName
Tags:
, create new tag

Bug: Formatted Search uses title but should use name for formfield parameter

documenation for FormattedSearch says $formfield(name) but actually uses $formfield(title). Should use the meta field name.

Test case

The documentation for FormattedSearch is a bit inaccurate for $formfield(name). In fact the code picks up $formfield(title). This can be a problem if the title is not a WikiWord. For example, in the case I was working on, I find the following META tags at the bottom of the topic file:

META:FORM{name="BuyerForm"}%
META:FIELD{name="BuyerType" title="BuyerType" value="ComputerHardwareMfg, TeleCom"}%
META:FIELD{name="Region" title="[[Region]]" value="NorthAmericaRegion"}%
META:FIELD{name="CompanyRevenue2002MilUS" title="Company Revenue 2002 (Mil US$)" value="18915"}%
META:FIELD{name="CompanyRevenue2001MilUS" title="Company Revenue 2001 (Mil US$)" value="21790"}%

This works (clumsily) for something like

$formfield([[Region]])

But blows everything up if you use the more complex

$formfield(Company Revenue 2002 (Mil US$))

I think it would be better to use the "name" field above, so that the documentation is correct. It is probably generally improper to use the title of the META field for processing. To fix this, make the following minor change in Search.pm:

sub getMetaFormField
...snip...
        $title = $field->{"title"};          # should change to $title = $field->{"name"};
        $value = $field->{"value"};
        $value =~ s/^\s*(.*?)\s*$/$1/go;
        if( $title eq $name ) {
            $value = breakName( $value, $break );
            return $value;

-- RaymondLutz - 17 Oct 2003

Environment

TWiki version: TWikiRelease01Feb2003
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: RedHat Linux
Web server: Apache
Perl version:  
Client OS: WinXP?
Web Browser: IE

-- RaymondLutz - 17 Oct 2003

Follow up

Fix record

You are right about the usefulness of name vs title. I could not simply change from title to name because this would break existing applications that assume title. So I fixed it to look for name and title, this makes it behave the way users expect, and also should not break existing apps.

Change:

Index: Search.pm
===================================================================
--- Search.pm   (revision 1590)
+++ Search.pm   (working copy)
@@ -1124,14 +1124,12 @@
         $name = $params[0] || "";
         $break = $params[1] || 1;
     }
-    my $title = "";
     my $value = "";
     my @fields = $theMeta->find( "FIELD" );
     foreach my $field ( @fields ) {
-        $title = $field->{"title"};
         $value = $field->{"value"};
         $value =~ s/^\s*(.*?)\s*$/$1/go;
-        if( $title eq $name ) {
+        if( $name =~ /^($field->{"name"}|$field->{"title"})$/ ) {
             $value = breakName( $value, $break );
             return $value;
         }

Change is in SVN.

-- PeterThoeny - 23 Jul 2004

Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r2 < r1 | More topic actions
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback SourceForge.net Logo