From: Aaron Trevena Date: Tue, 7 Feb 2006 16:15:09 +0000 (+0000) Subject: making Untainting less awful X-Git-Tag: 2.11~64 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=e2d49ea38932b4cde8cd821418a513ce7ced8337;p=maypole.git making Untainting less awful git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@454 48953598-375a-da11-a14b-00016c27c3ee --- diff --git a/Changes b/Changes index 0792dae..5ccf775 100644 --- a/Changes +++ b/Changes @@ -52,6 +52,8 @@ API additions and enhancements: - Improved factory templates - added the status() attribute, although it's not used in many places yet + Maypole::Model::CDBI + - improved error messages in do_edit action Bug fixes: Fix to cgi_maypole.t (bug 11346) diff --git a/lib/Maypole/Model/CDBI.pm b/lib/Maypole/Model/CDBI.pm index 5013d4f..32f36b9 100644 --- a/lib/Maypole/Model/CDBI.pm +++ b/lib/Maypole/Model/CDBI.pm @@ -77,7 +77,25 @@ sub do_edit : Exported { if (%errors) { # Set it up as it was: $r->template_args->{cgi_params} = $r->params; - $r->template_args->{errors} = \%errors; + + # + # replace user unfriendly error messages with something nicer + + foreach (@{$config->{$table}->{required_cols}}) { + next unless ($errors{$_}); + my $key = $_; + s/_/ /g; + $r->template_args->{errors}{ucfirst($_)} = 'This field is required, please provide a valid value'; + $r->template_args->{errors}{$key} = 'This field is required, please provide a valid value'; + delete $errors{$key}; + } + + foreach (keys %errors) { + my $key = $_; + s/_/ /g; + $r->template_args->{errors}{ucfirst($_)} = 'Please provide a valid value for this field'; + $r->template_args->{errors}{$key} = 'Please provide a valid value for this field'; + } undef $obj if $creating; $r->template("edit"); @@ -102,7 +120,9 @@ sub _do_update_or_create { eval { $obj->update_from_cgi( $h => { required => $required_cols, ignore => $ignored_cols, - } ) }; + } ); + $obj->update(); # pos fix for bug 17132 'autoupdate required by do_edit' + }; $fatal = $@; } else { eval { diff --git a/lib/Maypole/View/TT.pm b/lib/Maypole/View/TT.pm index 7106b7a..b837e52 100644 --- a/lib/Maypole/View/TT.pm +++ b/lib/Maypole/View/TT.pm @@ -32,8 +32,7 @@ sub template { if ($self->{tt}->process($template_file, { $self->vars($r) }, \$output )) { $r->{output} = $output; return OK; - } - else { + } else { $r->{error} = "TT error for template '$template_file'\n" . $self->{tt}->error; return ERROR; }