[Templates] Way of using CGI and checkboxes is giving problems

Mark Fowler mark@twoshortplanks.com
Mon, 25 Nov 2002 22:28:32 +0000 (GMT)


Rafael wrote:

> The checkbox fields, placed like:
> Active: [% query.checkbox({name=>'ACTIVE',label=>" "}) %]
> are causing the [% query.end_form %] at the end of the form to appear as:
> ARRAY(0x12345).

Try running this:

  #!/usr/bin/perl

  use CGI;
  use Data::Dumper;

  my $q = CGI;
  print Dumper [$q->checkbox(-name => "foo")];
  print Dumper [$q->end_form];

This prints out:

  $VAR1 = [
            '<input type="checkbox" name="foo" value="on" />foo'
          ];
  $VAR1 = [
            '<input type="hidden" name=".cgifields" value="foo" />',
            '</form>'
          ];

You can see that end_form is now actually returning two values (including
a hidden form.)  TT treats this as a list ref.  You probably want to
simply join them, which can be done like so:

  [% query.end_form.list.join %]

The .list. bit ensures that end_form is a list (even if it has just one
element.  The virtual methods are described in the manual here:

http://www.template-toolkit.org/docs/leon/Manual/VMethods.html

Hope that's helpful.

Mark.

-- 
s''  Mark Fowler                                     London.pm   Bath.pm
     http://www.twoshortplanks.com/              mark@twoshortplanks.com
';use Term'Cap;$t=Tgetent Term'Cap{};print$t->Tputs(cl);for$w(split/  +/
){for(0..30){$|=print$t->Tgoto(cm,$_,$y)." $w";select$k,$k,$k,.03}$y+=2}