aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Roles/ConfirmValidation.pm
blob: 776230287d19d86192e4d7079d0c1ff7f33ee83a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package FixMyStreet::Roles::ConfirmValidation;
use Moo::Role;

=head1 NAME

FixMyStreet::Roles::ConfirmValidation - role for adding standard confirm validation

=head1 SYNOPSIS

This is applied to a Cobrand class to add validation of reports using standard
Confirm field lengths.

    use Moo;
    with 'FixMyStreet::Roles::ConfirmValidation';

=cut

has max_report_length => ( is => 'ro', default => 2000 );

sub report_validation {
    my ($self, $report, $errors) = @_;

    if ( length( $report->name ) > 50 ) {
        $errors->{name} = sprintf( _('Names are limited to %d characters in length.'), 50 );
    }

    if ( length( $report->user->phone ) > 20 ) {
        $errors->{phone} = sprintf( _('Phone numbers are limited to %s characters in length.'), 20 );
    }

    if ( length( $report->detail ) > $self->max_report_length ) {
        $errors->{detail} = sprintf( _('Reports are limited to %s characters in length. Please shorten your report'), $self->max_report_length );
    }

    return $errors;
}

1;