HI all, I'm rather new to the TT, but so far I'm liking it's flexibility. The badger book is a great resource as well. But, I'm having an issue I can't seem to find an answer to and am hoping the list can help me.

I want to populate a drop down box with data from a database. I'm pulling the factory name from a table to put in the drop down box so that the user can select which factory to pull shift reports from. Here's what I have so far:

in the .pl file:

 my $cgi = new CGI;
    my $dbh = DBI->connect(config('data_source'), config('username'), 
config('password'));
    my $dao = EmbMon::DAO->new($dbh);
    my $sql = qq/SELECT abbreviation from factory/;
    my $sth = $dbh->prepare($sql);
    $sth->execute();

    while ($row = $sth->fetchrow_array)
    {
    push @rows, $row;
    }

    my $file = 'shift_rpt.html';
    my $vars = {
        'cgi' =>CGI->new(),
        'version' => "0.5.8.2012",
        'factory' => \@rows
    };

    $template->process($file, $vars)
        || die "Template process failed: ", $template->error(), "\n";


in the HTML template:

<form name="myform" method="POST" action="/cgi-bin/shift_rpt.cgi">

[% FOREACH factory IN factory %]
    <p style="text-align: left;"><strong>Select Factory:</strong><br><select 
name="factory"><OPTION>
    <option value=some_value>$factory</option>
    </select>
    <input class="button" type="submit" value="Run Report">

</form>


Is this the proper way to do this, or is there a better/more flexible way? Am I missing something?

--

Mark Haney
Software Developer/Consultant
AB Emblem
ma...@abemblem.com
Linux marius.homelinux 3.3.4-3.fc16.x86_64 GNU/Linux

_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to