This may be the worng place to ask a question, but I think I am right
PerlMonks 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 populated
I 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.
$ cat sample.txt a 5 b 6 c 7 d 8
cfb.pl
#!/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; }
Output:
$ 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.