| CGI-Ex-Recipes documentation | Contained in the CGI-Ex-Recipes distribution. |
CGI::Ex::Recipes::Add - Implements the creation of a new recipe!
Version 0.02
Perhaps a little code snippet.
sub skip { 0 }
sub name_step { 'edit' }
...
See the general documentations for these methods in CGI::Ex::App
Returns edit in order the edit.tthtml template to be used
The real work is done here. First checks for abs record in the recipes table with the same title and if found adds an error to the template. Otherwise inserts the new record. See the code foreach details.
Красимир Беров, <k.berov at gmail.com>
Not known
perldoc CGI::Ex::Recipes
Copyright 2007 Красимир Беров, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| CGI-Ex-Recipes documentation | Contained in the CGI-Ex-Recipes distribution. |
package CGI::Ex::Recipes::Add; use utf8; use warnings; use strict; use base qw(CGI::Ex::Recipes); our $VERSION = sprintf "%d.%03d", q$Revision 0.001$ =~ /(\d+)/g; sub skip { 0 } sub name_step { 'edit' } sub finalize { my $self = shift; my $form = $self->form; my $s = "SELECT COUNT(*) FROM recipes WHERE title = ?"; my ($count) = $self->dbh->selectrow_array($s, {}, $form->{'title'}); if ($count) { $self->add_errors(title => 'A recipe by this title already exists'); return 0; } $s = "INSERT INTO recipes (pid, is_category, title, problem, analysis, solution, sortorder, tstamp, date_added) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; my $tstamp = $self->now; $self->dbh->prepare($s)->execute( $form->{'pid'}, $form->{'is_category'}||0, $form->{'title'}, $form->{'problem'}, $form->{'analysis'}, $form->{'solution'}, $form->{'sortorder'}, $tstamp, $tstamp,); $self->add_to_form(success => "Recipe added to the database"); return 1; } 1; # End of CGI::Ex::Recipes::Add __END__