Thanks George and Clayton. All that fixed it right up. If you find
yourself in Atlanta, drinks are on me.

On 7/19/07, Clayton Scott <[EMAIL PROTECTED]> wrote:
Hi Jay,

This is really a Template Toolkit issue.
These are your offending lines:

> my $params = { id => $id };
 > return $self->tt_process('article_form.tt', $params);

You are only passing the 'id' to your template.

In your template you have:
[% id.body %]

but id.body doesn't exist because id is just the article id from your
database.

If you wanted the template to work as is, I would make the following
changes:

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 article's details
    my $article = $self->_retrieve_article_details($id) if
$id;


    my $params = { id => $article };
    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 $article = $sth->fetchrow_hashref();

   return $article;
}



--
Clayton Scott
[EMAIL PROTECTED]





On 7/18/07, Jay Varner <[EMAIL PROTECTED]> wrote:
>
> I'm not sure if this is a CGI::Application or a Template Toolkit problem,
but...
>
> I'm trying to translate Dan Horne's 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 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>
>
> [% id.title %]
>
>     <tr>
>       <td colspan="2"><input type="Submit" value="Save"></td>
>     </tr>
>   </table>
>   <input type="Hidden" name="id" value="[% id %]">
>   <input type="Hidden" name="rm" value="maintain_article">
> </form>
>
> [% PROCESS footer %]
>
> No values show up. If I use just [% id %] it will print the id value
> in the url 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]
>
>



--

Clayton Scott
[EMAIL PROTECTED]

---------------------------------------------------------------------
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]

Reply via email to