aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Admin.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2014-10-07 17:01:28 +0100
committerMatthew Somerville <matthew@mysociety.org>2014-10-08 16:04:54 +0100
commitf062193076b5caaceebd9f1dae62c01234c3f3b1 (patch)
tree7921bbd4696010f76bdde4ae33d6614686edbc76 /perllib/FixMyStreet/App/Controller/Admin.pm
parentcf866de4b2e9d402c4333c083f35d0d7ec99142c (diff)
Validate category name/email/note in admin.
This prevents the creation of a category with a blank name. Fixes #556.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm11
1 files changed, 10 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index cfe165f43..c1df8622f 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -343,8 +343,13 @@ sub update_contacts : Private {
if ( $posted eq 'new' ) {
$c->forward('check_token');
+ my %errors;
+
my $category = $self->trim( $c->req->param( 'category' ) );
+ $errors{category} = _("Please choose a category") unless $category;
my $email = $self->trim( $c->req->param( 'email' ) );
+ $errors{email} = _('Please enter a valid email') unless is_valid_email($email);
+ $errors{note} = _('Please enter a message') unless $c->req->param('note');
$category = 'Empty property' if $c->cobrand->moniker eq 'emptyhomes';
@@ -367,7 +372,11 @@ sub update_contacts : Private {
$contact->api_key( $c->req->param('api_key') );
$contact->send_method( $c->req->param('send_method') );
- if ( $contact->in_storage ) {
+ if ( %errors ) {
+ $c->stash->{updated} = _('Please correct the errors below');
+ $c->stash->{contact} = $contact;
+ $c->stash->{errors} = \%errors;
+ } elsif ( $contact->in_storage ) {
$c->stash->{updated} = _('Values updated');
# NB: History is automatically stored by a trigger in the database