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

UPDATE: Looks like there was some issues with my HTML:

<!--TMPL_INCLUDE name="header.html"--> <p>Sign our guestbook!</p> <form action="" method="post"> <input type="hidden" name="create" value="yes" /> <input type="hidden" name="m" value="sign" /> <-- needed this to post +to the correct run mode <p>Name:<input type="text" name="name" /></p> <p>Email:<input type="text" name="email" /><input type="checkbox" name +="hide_email" /> Hide email</p> <p>Website:<input type="text" name="website" value="http://" /></p> <p>Comments:</p> <p><textarea name="comments" rows="10" columns="45"></textarea></p> <p><input type="submit" name="Post your comment" /></p> </form> <!--TMPL_INCLUDE name="footer.html"-->

Howdy all,

I just started using DBIx::Class, in lieu of Class::DBI basically. Retrieving is going great however I seem to be having some troubles createing.

UPDATE:Apparently I wasn't clear enough when i said that the record wasn't being created at all, there are no error messages being returned, the script just isn't creating a record.

My code is posted below, I think all that is posted is necessary to see the issue, along with the HTML form.

Let me know if you have any ideas...

Code:

sub sign { my $self = shift; my $q = $self->query; my $tmpl = $self->load_tmpl( 'comment.html', %config_vars ); ############################# # cleaning the HTML # we use HTML::Scrubber to clean up the HTML so our code doesn't b +reak use HTML::Scrubber; my $name = $q->param('name'); my $email = $q->param('email'); my $website = $q->param('comments'); my $hide_email = $q->param('hide_email'); my $comments = $q->param('comments'); # let's create an array of the params in this form: my @form_data = ( $name, $email, $website, $comments, $hide_email +); # the HTML::Scrubber object # allow <br /> <p> <b> <i> <u> <hr /> # this will be put into a config file eventually (aka upon product +ion) my $scrubber = HTML::Scrubber->new( allow => [ qw[ p b i u hr br ] + ] ); # deny list # deny <link> <a> *<script>*<- especially, <style> $scrubber->deny( qw[ link a href script style ] ) ; # scrub all the form data passed to this script... $scrubber->scrub( $_ ) for @form_data; ############################## # time to create a new comment... my $comment; if ( $q->param('create') eq "yes" ) { $comment = $schema->resultset('Comments')->create( { name => $name, email => $email, website => $website, comments => $comments, hide_email => $hide_email, } ); $comment->update; return qq{Thank you for your comments! <a href='?'>&laquo;back +</a>}; } $tmpl->output unless $q->param('create'); }

HTML(with HTML::Template tags):

<!--TMPL_INCLUDE name="header.html"--> <p>Sign our guestbook!</p> <form action="" method="post"> <input type="hidden" name="create" value="yes" /> <p>Name:<input type="text" name="name" /></p> <p>Email:<input type="text" name="email" /><input type="checkbox" name +="hide_email" /> Hide email</p> <p>Website:<input type="text" name="website" value="http://" /></p> <p>Comments:</p> <p><textarea name="comments" rows="10" columns="45"></textarea></p> <p><input type="submit" name="Post your comment" /></p> </form> <!--TMPL_INCLUDE name="footer.html"-->
meh.

Replies are listed 'Best First'.
Re: Problems with DBIx::Class and CGI::Application
by grep (Monsignor) on Sep 22, 2006 at 05:12 UTC
    My code is posted below, I think all that is posted is necessary to see the issue, along with the HTML form.

    Not really. You failed to give us any info on the error messages you recieve or even the specifics on what is going wrong (ex. 'The record doesn't create at all' or 'One of the fields doesn't populate' or 'the browser get annoyed, and then makes a PFFFT sound'). If you had looked up any error messages, you would have also been able to pare the code down to a few lines, making it easier for us read. Please read How (Not) To Ask A Question.

    Assuming $schema is in scope from above, your syntax looks fine. So the answer will be in the error messages. Look in the webserver error log or run some test cases from the command line.



    grep
    Mynd you, mønk bites Kan be pretti nasti...

      My mistake grep, i thought when I said that it was having troubles creating that it would be enough

      As it stands, no errors are being returned, so i'll have to delve deeper into my code until i find a solution or something comes up on here.

      meh.
        If you're not see error messages. Run the program from the command line with the debugger.

        A couple of hints:
        Use Mozilla and LiveHTTPHeaders to get the args.
        Set a breakpoint around my $comment.
        Then inspect the vars and step through the create routine.



        grep
        Mynd you, mønk bites Kan be pretti nasti...
        If you don't pass AutoCommit => 1 to connect, you'll be in a transaction. And I don't see a commit call. Bet that's your problem (Class::DBI forces it on for MySQL, we don't) -- mst (yes, one day I'll register)
Re: Problems with DBIx::Class and CGI::Application
by chromatic (Archbishop) on Sep 22, 2006 at 06:33 UTC

    As a side note, this code won't do anything useful, as you use the $name et al variables later unmodified:

    # scrub all the form data passed to this script... $scrubber->scrub( $_ ) for @form_data;

      Good point, chromatic. Should have done something more along the lines of my $name = $scrubber->scrub( $q->param('name') )

      Seems i'm making some stupid mistakes in this app, sleep ++ :-/

      meh.
Re: Problems with DBIx::Class and CGI::Application
by initself (Monk) on Sep 22, 2006 at 05:30 UTC
    I don't think you need ->update with create() using DBIx::Class. create() "inserts a record into the resultset and returns the object representing it." That being said, the syntax on your create() statement looks fine. First place I would check would be your error logs.