Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

CGI::Formbuilder and Class::DBI

by set_uk (Pilgrim)
on Nov 12, 2003 at 11:07 UTC ( [id://306507]=perlquestion: print w/replies, xml ) Need Help??

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

From an href I am entering a CGI::Application runmode with a request_id reference which displays a CGI::Formbuilder form. I want to populate this form with the values of the record from the database which I obtain via a Class::DBI->retrieve on my class. Form builder takes a hashref - Class::DBI provides accessor methods for the fields. Whats the quickest way to iterate through all the Class::DBI fields and generate a hashref for CGI::Formbuilder?

Is it simply a case of iterating through all the fields via the fields array I used to create the CGI::Form and then using  $value = $obj->get($column_name) to create the hash? I bet there is a better way.

btw - I'm impressed with the ease with which a webapp can be out together using CGI, CGI::FormBuilder, Template Toolkit, CGI::Application. Complete web app newbie last week - almost finished this week. Thumbs up to the authors who penned those modules.

Simon

Replies are listed 'Best First'.
Re: CGI::Formbuilder and Class::DBI
by PodMaster (Abbot) on Nov 12, 2003 at 11:54 UTC
    my $hashref = { map { $_ => $obj->get($_); } $obj->columns };
    This should work for simple objects

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Marvellous - Spot on.

      Thanks

Re: CGI::Formbuilder and Class::DBI
by markjugg (Curate) on Nov 13, 2003 at 03:26 UTC
    I'd say the quickest way is to avoid the complexity of adding Class::DBI to the mix, and use the DBI interface directly:
    my $href = $DBH->selectrow_hashref("SELECT f1,f2 FROM t WHERE id = 23" +);

    Mark

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://306507]
Approved by Roger
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found