--- /Users/arthurclemens/Desktop/TWiki.pm.org Mon Jan 19 08:18:06 2004 +++ /Users/arthurclemens/Desktop/TWiki.pm Sun Feb 22 00:51:57 2004 @@ -2195,6 +2195,7 @@ &TWiki::Prefs::handlePreferencesTags( $text ); handleInternalTags( $text, $theTopic, $theWeb ); + $text =~ s/%FORMFIELD{(.*?)}%/&getFormField($theWeb,$theTopic,$1)/ge; $text =~ s/%TOC{([^}]*)}%/&handleToc($text,$theTopic,$theWeb,$1)/ge; $text =~ s/%TOC%/&handleToc($text,$theTopic,$theWeb,"")/ge; @@ -2981,5 +2982,57 @@ $result =~ s|\n?\n$||o; # clean up clutch return "$head$result"; } + +sub getFormField +{ + my( $web, $topic, $args ) = @_; + my ( $meta, $dummyText ) = &TWiki::Store::readTopic( $web, $topic ); + my $text = ""; + my $formTopic; + my $formTopicWeb; + my $prefix = ""; + my $suffix = ""; + my $altText = ""; + my $found = 0; + + my $formField = extractNameValuePair( $args ); + $formTopic = extractNameValuePair( $args, "topic" ); + $prefix = extractNameValuePair( $args, "prefix" ); + $suffix = extractNameValuePair( $args, "suffix" ); + $altText = extractNameValuePair( $args, "alttext" ); + + if ($formTopic) { + if ($topic =~ /^([^.]+)\.([^.]+)/o) { + ( $formTopicWeb, $topic ) = ( $1, $2 ); + } else { + $formTopicWeb = extractNameValuePair( $args, "web" ); + } + ( $meta, my $dummyText ) = &TWiki::Store::readTopic( $formTopicWeb, $formTopic ); + } else { + ( $meta, my $dummyText ) = &TWiki::Store::readTopic( $web, $topic ); + } + + my %form = $meta->findOne( "FORM" ); + if( %form ) { + my $name = $form{"name"}; + my @fields = $meta->find( "FIELD" ); + foreach my $field ( @fields ) { + my $title = $field->{"title"}; + if( $title eq $formField ) { + my $value = $field->{"value"}; + if (length $value) { + $found = 1; + $text = $prefix . $value . $suffix; + last; #one hit suffices + } + } + } + } + if (!$found) { + $text = $altText; + } + $text = getRenderedVersion( $text, $web ); + return $text; +} 1;