This may be the worng place to ask a question, but I think I am rightPerlMonks is just the right place to ask, as well as FB website (they have official mailing list at fbusers-subscribe@formbuilder.org), or, perhaps, CPAN Forum (though it seems very quiet).
print "Content-type: text/html\n\n";Oh come on, you're using CGI but left out its header() method? :-)
# for debugging to se if the hash was populatedI think you'd be better to use Data::Dumper or other similiar modules from CPAN.
In my debugging portion, the hash prints with the proper data from the database, however the values do not get loaded as defaults on the form.Unfortunately, you didn't show the (sample) code of what your debugging portion threw out. However, I emulate this by reading the data from external file and it works just fine. The two approaching might be incompatible in some way, but I take the essence that the data to be assigned is external.
cfb.pl$ cat sample.txt a 5 b 6 c 7 d 8
Output:#!/usr/bin/perl use strict; use warnings; use CGI::FormBuilder; my @fields = qw(a b c d); my %values = get_values(shift || ''); my $form = CGI::FormBuilder->new(fields => \@fields, values => \%value +s); print "$_ => ", $form->field($_), "\n" for @fields; sub get_values { my $way = shift; return (a => 1, b => 2, c => 3, d => 4) unless $way; my %fetched; if ($way eq 'file') { open my $fh, '<', 'sample.txt' or die "open failed: $!\n"; while (<$fh>) { chomp; my($key, $value) = split; $fetched{$key} = $value; } close $fh; } # additional if?? return %fetched; }
$ perl cfb.pl a => 1 b => 2 c => 3 d => 4 $ perl cfb.pl file a => 5 b => 6 c => 7 d => 8
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
In reply to Re: Setting Default Values using CGI::FormBuilder
by naikonta
in thread Setting Default Values using CGI::FormBuilder
by nakajima
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |