bradcathey has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monasterians,

I'm I have gotten HTML::FillInForm to populate a form using a somewhat busy bunch of code:

my $q = new CGI; $q -> param(-name => 'choices', -value => '2'); $q -> param(-name => 'address', -value => '123 Main Street'); my $template = HTML::Template->new( filename => "../form.tmpl"); my $html = $template->output; my $form = new HTML::FillInForm; my $page = $form->fill(scalarref => \$html, fobject => $q); print "Content-type: text/html\n\n"; print $page;

The doc for HTML::FillInForm says that the fobject will accept a hash ref, but I this returns an "unblessed" error:

my $q = new CGI; my $info = [ { -name => 'address', -value => '123 Main' }, { -name => 'choices', -value => '2'} ]; my $template = HTML::Template->new( filename => "../form.tmpl"); + my $html = $template->output; my $form = new HTML::FillInForm; my $page = $form->fill(scalarref => \$html, fobject => $info); print "Content-type: text/html\n\n"; print $page;

I would like to loop through data from by db table to populate this hash. Is there a way to do this cleanly? Or am I just not getting this? Thanks!

Update: Please see my findings, which are under the review of the HTML::FillInForm module itself.


—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Replies are listed 'Best First'.
Re: Trying to pass a hash ref to a module
by davido (Cardinal) on May 17, 2005 at 20:00 UTC

    my $page = $form->fill(scalarref => \$html, fobject => $info);

    Change 'fobject' to 'fdat'. The 'fobject' parameter expects an object ref. 'fdat' will accept a hashref or apparently an arrayref too (according to the docs).


    Dave

      davido, thanks for the lead I miss not be getting the hash right. How does one have a hash with lots of values that have the same key, other than using an Array of Hashes?

      Anyway, I tried this--no error, but nothing got populated on the form.

      my $q = new CGI; my @info = { 'address' => '123 Main', 'choices' => '2' }; my $template = HTML::Template->new( filename => "../form.tmpl"); my $html = $template->output; my $form = new HTML::FillInForm; my $page = $form->fill(scalarref => \$html, fdat => \@info); print "Content-type: text/html\n\n"; print $page;

      Ideas?


      —Brad
      "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
        Change @info and \@info to simply $info.

        my $info = { address => '123 Main', choices => '2' };
        and
        my $page = $form->fill(scalarref => \$html, fdat => $info);

        The docs for HTML::FillInForm states 'To pass multiple values using %fdat use an array reference'. At first read, this might lead you to think that you could pass an array reference instead of a hash reference, but what they actually mean is to use an array reference within the hash reference to specify multiple values for a given key.

        my $info = { address => '123 Main', choices => [ '2', '3', '4' ] };

Re: Trying to pass a hash ref to a module
by jdporter (Paladin) on May 17, 2005 at 19:59 UTC
    What it's talking about is a ref to an array of CGI objects. Specifically, fobject can either be a single CGI object, or an array(ref) of CGI objects.
Re: Trying to pass a hash ref to a module
by mrborisguy (Hermit) on May 17, 2005 at 19:57 UTC
    you're getting an error because $info isn't a hash ref, it's an array ref with one element. try changing the square brackets in that line to curly brackets, and see what happens.

    Update:
    You know what... i'm an idiot, what i told you doesn't even make sense at all!