I'm not sure if this is a CGI::Application or a Template Toolkit problem, but...
I'm trying to translate Dan Horne's nice tutorial on sitepoint.com (http://www.sitepoint.com/article/cgi-application) to use the Template Toolkit. I seem to be getting it all but populating the edit forms. Adding new records work fine. Listing all the records is flawless. Using the original example with the HTML::Template works just as it should, but I really don't want to use the HTML::Template. I'm really new to CGI::Application and I'm sure I'm missing something obvious. Here is my code based of Horne's example (though I'm using it to list articles and not users): sub display_article_form { my $self = shift; my $errs = shift; my $q = $self->query; my $id = $q->param('id') || 0; # If we have an article id, then get the articles's details $self->_retrieve_article_details($id) if ($id); my $params = { id => $id }; return $self->tt_process('article_form.tt', $params); } ....... sub _retrieve_article_details { my $self = shift; my $id = shift; my $sql = "SELECT * FROM articles WHERE id = ?"; $self->dbh->{PrintError} = 0; $self->dbh->{RaiseError} = 1; my $sth = $self->dbh->prepare($sql); $sth->execute($id); my $rs = $sth->fetchrow_hashref(); # Save each column (field) value in CGI::Application parameter foreach my $article_field (keys %$rs) { $self->param($article_field, $rs->{$article_field}); } } ..... And then the template when called from mysite.net/myapp.pl?rm=display_article_form&id=13 [% PROCESS site.html %] <form action="" method="post"> <table> <td>Title*</td> <td><input type="Text" name="title" size="15" value="[% id %]"> </td> </tr> <tr> <td>Body*</td> <td><textarea name="body" cols="40" rows="20"> [% id.body %] </textarea></td> </tr> <tr> <td colspan="2"><input type="Submit" value="Save"></td> </tr> </table> <input type="Hidden" name="id" value="[% id.id %]"> <input type="Hidden" name="rm" value="maintain_article"> </form> [% PROCESS site.footer %] The template renders the the page just as it should but no values show up in the fields. If I use just [% id %] it will print the id value in the uri but it does not seem to actually be pulling the values from the db. The same template works fine for adding a new article. And again, the HTML::Template from the original example works fine. Thoughts? Jay --------------------------------------------------------------------- Web Archive: http://www.mail-archive.com/[email protected]/ http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
