• Do not register here on develop.twiki.org, login with your twiki.org account.
• Use View topic Item7848 for generic doc work for TWiki-6.1.1. Use View topic Item7851 for doc work on extensions that are not part of a release. More... Close
• Anything you create or change in standard webs (Main, TWiki, Sandbox etc) will be automatically reverted on every SVN update.
Does this site look broken?. Use the LitterTray web for test cases.

Item6155: FORMFIELD does not expand documented attributes and is missing literal tokens

Item Form Data

AppliesTo: Component: Priority: CurrentState: WaitingFor: TargetRelease ReleasedIn
Engine RenderDotPm Normal New   n/a  

Edit Form Data

Reported By:
Applies To:
Current State:
Waiting For:
Target Release:
Released In:


FORMFIELD does not expand $name, $attributes, $type, $size and $definingTopic, although it is documented to do so.

Also, it is missing $n, $nop, $quot, $percnt & $dollar (as in formatted search). The $n is particularly annoying right now; I want to emit a
when a form field is non-null.

I looked at Render.pm, where FORMFIELD is rendered.

  1. $name is easy to add.
  2. $definingTopic - We can do this, given the (documented) restriction of only one form per topic. If the restriction is lifted, doing it efficiently would require backpointers in the metadata.
  3. $attributes, $type, $size - I assume the intent is to work back to the topic that defines the form. I don't think we can do this without adding metadata. Only the form defintion topic has this information. We can find that, but we don't know what revision was used when the form was attached. I think this needs to be considered and handled by someone with more time & context.
  4. The literal tokens are trivial.

Here is an example of why $n is useful. There are several chunks of optional attribute data that are materialized when present. They want their own paragraphs - but not whitespace when missing. Before suggesting %<nop>IF, clearly one really only wants to evaluate (much less type!) something like this once. (The example looks nonsensical because I have replaced sensitive variable names. The intent here is to show structure.)

%FORMFIELD{"LeaveType" topic="%INCLUDINGTOPIC%" format="$n%FORMFIELD{"PronounHe" topic="%INCLUDINGTOPIC%"}% took leave $value%FORMFIELD{"LeavePlace" topic="%INCLUDINGTOPIC%" format=" in $value"}%%FORMFIELD{"LeaveDate" topic="%INCLUDINGTOPIC%" format=" on $value"  }%." }%

Here is a patch for items 1, 2, and 4. After due consideration, someone else needs to either fix item 3 or correct the documentation.

--- lib/TWiki/Render.pm~        2008-09-11 23:41:58.000000000 -0400
+++ lib/TWiki/Render.pm 2008-12-22 12:53:20.000000000 -0500
@@ -842,10 +842,23 @@
                 $found = 1;
                 my $value = $field->{value};
                 if (length $value) {
                     $text = $format;
+                   $text =~ s/\$name/$field->{name}/g;
+                   if( $format =~ m/\$definingTopic/ ) {
+                       my @defform = $meta->find('FORM');
+                       my $form = $defform[0];  #TWiki only supports one form per topic
+                       my $fname = $form->{name};
+                       $text =~ s/\$definingTopic/$fname/g;
+                   }
+                   $text =~ s/\$n/\%BR\%/g;
+                   $text =~ s/\$quot/\"/g;
+                   $text =~ s/\$percnt/\%/g;
+                   $text =~ s/\$dollar/\$/g;
                     $text =~ s/\$value/$value/go;
                 } elsif ( defined $default ) {
                     $text = $default;
                 last; #one hit suffices

-- TWiki:Main/TimotheLitt - 22 Dec 2008

Good catch! Since you have check-in rights to the core, could you fix it in trunk and 4.2 branch?

-- TWiki:Main.PeterThoeny - 23 Dec 2008

Since $definingTopic is not yet implemented I suggest to use a more intuitive name and to be consistent use lowercase only. May be $formtopic or $formdefinitiontopic?

-- TWiki:Main.PeterThoeny - 23 Dec 2008

The fork used $form (See http://foswiki.org/Tasks/Item549), so you might want to be consistent with them. They also used a slightly different patch that uses an standard routine to expand escapes.

As for checking it in - I've never figured out the mechanics.

As I've pointed out before, you don't make it easy. And if I checkin here, I'll have to do the same work again on the fork. I don't have the bandwidth to tix things in three places (my system + two forks.) I am happy to share what I find/fix.

Hopefully someone with more bandwidth than I have can handle the checkin.

-- TWiki:Main.TimotheLitt - 11 Jan 2009

Summary FORMFIELD does not expand documented attributes and is missing literal tokens
ReportedBy TWiki:Main.TimotheLitt
Codebase 4.2.3
SVN Range TWiki-5.0.0, Wed, 22 Oct 2008, build 17677
AppliesTo Engine
Component RenderDotPm
Priority Normal
CurrentState New


TargetRelease n/a

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View |  Raw edit | More topic actions
Topic revision: r3 - 2009-01-11 - TimotheLitt
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2023 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback