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

Oh Venerable Brothers of the #!
I need help! I would like to create a Dynamic form which will change with the output from a database query
Using input from a Database Table

The number of fields in the form will vary depending on the output of the Database Query

Users need to be able to provide input for each field

The resultant out put needs to be then uploaded into another database

Help!!!

How dow I create such a dynamic form and convert all the parameters into variables when the number of variable will change depending on the input from the user - I am using a multipart form and using CGI and DBI
Examples would be greatly appreciated

SQL Query:
select month_year, study_stage from study_stage_bymonth where studyid = 'abc'

Output example:
01-JAN-11 Start Up
01-FEB-11 Registering
01-MAR-11 Maintenance
01-APR-11 Maintenance
01-MAY-11 Maintenance
01-JUN-11 Maintenance
01-JUL-11 Maintenance
01-AUG-11 Maintenance
01-SEP-11 Maintenance
01-OCT-11 Maintenance
01-NOV-11 Maintenance
01-DEC-11 Close Out
01-JAN-12 Study Finished

output for study efg will be different

Help!!
Examples appreciated
  • Comment on How to I build a Dynamic Form from a Database output

Replies are listed 'Best First'.
Re: How to I build a Dynamic Form from a Database output
by CountZero (Bishop) on Aug 31, 2011 at 17:00 UTC
    For lack of enough specific information to give you a detailed answer, the standard answer is to use a templating engine, such as Template::Toolkit, probably as part of a dynamic web-framework such as Dancer or Catalyst.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: How to I build a Dynamic Form from a Database output
by duelafn (Parson) on Aug 31, 2011 at 20:57 UTC

    I have recently had success using HTML::FormFu (HTML::FormFu::Manual::Cookbook) to build up forms programmatically. The documentation focuses on YAML file examples, but you can build everything up using the populate and elements methods. Just turn each row into a hash describing the field and then pass them all in to the FormFu object. No ugly HTML munging!

    Good Day,
        Dean