<%args> $name $body $page_id <%init> use Comments::Comment qw(:all); use Comments::CommentObj; use JSON; # # This array is going to be populated with either # the data that was sent to the script, or the # error messages. # my %arr; my $comment = CommentObj->new($name, $body, $page_id); if($comment->validate(\%arr)) { # Everything is OK, insert to database: $comment->save; # Record time comment was saved. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); my $date = sprintf("%4d-%02d-%02d %02d:%02d:%02d", $year+1900, $mon, $mday, $hour, $min, $sec); $comment->date($date); # Outputting the markup of the just-inserted comment: print encode_json({'status'=>1,'html'=>$comment->markup()}); } else { # Outputtng the error messages $arr{status} = 0; print encode_json(\%arr) ; }