aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2014-04-09 17:09:14 +0100
committerStruan Donald <struan@exo.org.uk>2014-04-15 15:53:18 +0100
commit565c6498aefea0fd39ec7453019bbf86b52672dd (patch)
treefa11d5c90de95202da33086a56285b6a348aee88
parentb82228ce014cc87866d976eeb3ce6e454e87c336 (diff)
Add a who are you trying to contact option to contact form
In order to try and cut down on people mistakingly using this form to try and contact their council all some 'who are you trying to contact' options to the form that display appropriate messaged unless the 'FMS team option is selected. Add the validation code for this in the cobrand module. Fixes #41
-rw-r--r--perllib/FixMyStreet/App/Controller/Contact.pm5
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm8
-rw-r--r--perllib/FixMyStreet/Cobrand/FixMyStreet.pm18
-rw-r--r--t/app/controller/contact.t111
-rw-r--r--templates/web/default/contact/index.html2
-rw-r--r--templates/web/default/contact/who.html0
-rw-r--r--templates/web/fixmystreet/contact/blurb.html15
-rw-r--r--templates/web/fixmystreet/contact/index.html11
-rw-r--r--templates/web/fixmystreet/contact/who.html77
9 files changed, 246 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm
index 7ba18ed2d..6bc6e90ef 100644
--- a/perllib/FixMyStreet/App/Controller/Contact.pm
+++ b/perllib/FixMyStreet/App/Controller/Contact.pm
@@ -108,6 +108,11 @@ sub validate : Private {
if !mySociety::EmailUtil::is_valid_email( $c->req->param('em') );
}
+ %field_errors = (
+ %field_errors,
+ $c->cobrand->extra_contact_validation($c)
+ );
+
push @errors, _('Illegal ID')
if $c->req->param('id') && $c->req->param('id') !~ /^[1-9]\d*$/
or $c->req->param('update_id')
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 2de3eae5f..599ed5987 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -844,6 +844,14 @@ sub prettify_dt {
return Utils::prettify_dt( $dt, 1 );
}
+=head2 extra_contact_validation
+
+Perform any extra validation on the contact form.
+
+=cut
+
+sub extra_contact_validation { (); }
+
sub problem_as_hashref {
my $self = shift;
my $problem = shift;
diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
index c3a1f9d9d..ce62e206e 100644
--- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
+++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
@@ -21,5 +21,23 @@ sub title_list {
return undef;
}
+sub extra_contact_validation {
+ my $self = shift;
+ my $c = shift;
+
+ my %errors;
+
+ $c->stash->{dest} = $c->req->param('dest');
+
+ $errors{dest} = "Please enter who your message is for"
+ unless $c->req->param('dest');
+
+ if ( $c->req->param('dest') eq 'council' || $c->req->param('dest') eq 'update' ) {
+ $errors{not_for_us} = 1;
+ }
+
+ return %errors;
+}
+
1;
diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t
index 11e0d30cf..89a1db5b2 100644
--- a/t/app/controller/contact.t
+++ b/t/app/controller/contact.t
@@ -8,7 +8,7 @@ my $mech = FixMyStreet::TestMech->new;
$mech->get_ok('/contact');
$mech->title_like(qr/Contact Us/);
-$mech->content_contains("We'd love to hear what you think about this site");
+$mech->content_contains("It's often quickest to ");
my $problem_main;
@@ -282,6 +282,115 @@ for my $test (
};
}
+for my $test (
+ {
+ fields => {
+ em => 'test@example.com',
+ name => 'A name',
+ subject => 'A subject',
+ message => 'A message',
+ dest => undef,
+ },
+ page_errors =>
+ [ 'There were problems with your report. Please see below.',
+ 'Please enter who your message is for',
+ ]
+ },
+ {
+ fields => {
+ em => 'test@example.com',
+ name => 'A name',
+ subject => 'A subject',
+ message => 'A message',
+ dest => 'council',
+ },
+ page_errors =>
+ [ 'There were problems with your report. Please see below.',
+ 'You can only contact the team behind FixMyStreet using our contact form',
+ ]
+ },
+ {
+ fields => {
+ em => 'test@example.com',
+ name => 'A name',
+ subject => 'A subject',
+ message => 'A message',
+ dest => 'update',
+ },
+ page_errors =>
+ [ 'There were problems with your report. Please see below.',
+ 'You can only contact the team behind FixMyStreet using our contact form',
+ ]
+ },
+ )
+{
+ subtest 'check submit page incorrect destination handling' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ }, sub {
+ $mech->host('www.fixmystreet.com');
+ $mech->get_ok( $test->{url} ? $test->{url} : '/contact' );
+ $mech->submit_form_ok( { with_fields => $test->{fields} } );
+ is_deeply $mech->page_errors, $test->{page_errors}, 'page errors';
+
+ # we santise this when we submit so need to remove it
+ delete $test->{fields}->{id}
+ if $test->{fields}->{id} and $test->{fields}->{id} eq 'invalid';
+ is_deeply $mech->visible_form_values, $test->{fields}, 'form values';
+
+ if ( $test->{fields}->{dest} and $test->{fields}->{dest} eq 'update' ) {
+ $mech->content_contains( 'www.writetothem.com', 'includes link to WTT if trying to update report' );
+ } elsif ( $test->{fields}->{dest} and $test->{fields}->{dest} eq 'council' ) {
+ $mech->content_lacks( 'www.writetothem.com', 'does not include link to WTT if trying to contact council' );
+ $mech->content_contains( 'should find contact details', 'mentions checking council website for contact details' );
+ }
+ }
+ };
+}
+
+for my $test (
+ {
+ fields => {
+ em => 'test@example.com',
+ name => 'A name',
+ subject => 'A subject',
+ message => 'A message',
+ dest => 'help',
+ },
+ },
+ {
+ fields => {
+ em => 'test@example.com',
+ name => 'A name',
+ subject => 'A subject',
+ message => 'A message',
+ dest => 'feedback',
+ },
+ },
+ {
+ fields => {
+ em => 'test@example.com',
+ name => 'A name',
+ subject => 'A subject',
+ message => 'A message',
+ dest => 'from_council',
+ },
+ },
+ )
+{
+ subtest 'check email sent correctly with dest field set to us' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ }, sub {
+ $mech->clear_emails_ok;
+ $mech->get_ok('/contact');
+ $mech->submit_form_ok( { with_fields => $test->{fields} } );
+ $mech->content_contains('Thanks for your feedback');
+ $mech->email_count_is(1);
+ }
+ };
+}
+
$problem_main->delete;
done_testing();
diff --git a/templates/web/default/contact/index.html b/templates/web/default/contact/index.html
index 73e94fb33..8789fd03e 100644
--- a/templates/web/default/contact/index.html
+++ b/templates/web/default/contact/index.html
@@ -83,6 +83,8 @@
<label for="form_subject">[% loc('Subject:') %]</label>
<input type="text" class="required" name="subject" id="form_subject" value="[% subject | html %]" size="30"></div>
+[% INCLUDE 'contact/who.html' %]
+
[% IF field_errors.message %]
<div class="form-error">[% field_errors.message %]</div>
[% END %]
diff --git a/templates/web/default/contact/who.html b/templates/web/default/contact/who.html
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/templates/web/default/contact/who.html
diff --git a/templates/web/fixmystreet/contact/blurb.html b/templates/web/fixmystreet/contact/blurb.html
new file mode 100644
index 000000000..21a4ae715
--- /dev/null
+++ b/templates/web/fixmystreet/contact/blurb.html
@@ -0,0 +1,15 @@
+[% IF c.cobrand.moniker == 'fixmystreet' %]
+<h3>Send a message to FixMyStreet's technical support team</h3>
+
+<h4>If you have questions about FixMyStreet</h4>
+[% END %]
+
+<p>
+[% tprintf( loc("It's often quickest to <a href=\"%s\">check our FAQs</a> and see if the answer is there."), c.uri_for('/faq') ) %]
+</p>
+
+<p>
+[% loc('Please do <strong>not</strong> report problems through this form; messages go to
+the team behind FixMyStreet, not a council. To report a problem,
+please <a href="/">go to the front page</a> and follow the instructions.') %]
+</p>
diff --git a/templates/web/fixmystreet/contact/index.html b/templates/web/fixmystreet/contact/index.html
index dfef39b9f..44aa5c2e4 100644
--- a/templates/web/fixmystreet/contact/index.html
+++ b/templates/web/fixmystreet/contact/index.html
@@ -16,7 +16,11 @@
</aside>
</div>
+[% IF c.cobrand.moniker == 'fixmystreet' %]
+<h1>FixMyStreet technical support</h1>
+[% ELSE %]
<h1>[% loc('Contact the team') %]</h1>
+[% END %]
<form method="post" action="/contact/submit" class="validate">
<fieldset>
@@ -94,6 +98,7 @@
[% END %]
<input type="text" class="required" name="subject" id="form_subject" value="[% subject | html %]" size="30">
+ [% INCLUDE 'contact/who.html' %]
<label for="form_message">[% loc('Message') %]</label>
[% IF field_errors.message %]
@@ -107,6 +112,12 @@
</fieldset>
</form>
+<h4>[% loc("Don't like forms?") %]</h4>
+
+<p>
+[% tprintf( loc("You can contact technical support on <a href='mailto:%s'>%s</a>"), contact_email, contact_email) %]
+</p>
+
[% TRY %][% INCLUDE 'contact/address.html' %][% CATCH file %][% END %]
[% INCLUDE 'footer.html' pagefooter = 'yes' %]
diff --git a/templates/web/fixmystreet/contact/who.html b/templates/web/fixmystreet/contact/who.html
new file mode 100644
index 000000000..49f22b612
--- /dev/null
+++ b/templates/web/fixmystreet/contact/who.html
@@ -0,0 +1,77 @@
+[% IF c.cobrand.moniker == 'fixmystreet' %]
+ <h4>Topic:</h4>
+
+ [% IF field_errors.dest %]
+ <div class="form-error">[% field_errors.dest %]</div>
+ [% ELSIF field_errors.not_for_us %]
+ <div class="form-error">You can only contact the team behind FixMyStreet using our contact form</div>
+
+ [% IF dest == 'council' %]
+ <p>
+ We’re not the council: we just run this website which helps you report issues
+ to them.
+ </p>
+
+ <p>
+ <strong>If you want to report a street problem</strong>, return to the
+ FixMyStreet homepage and enter your postcode. You can then make a report.
+ We'll send it to your council, and publish it on FixMyStreet.
+ </p>
+
+ <p>
+ <strong>If your problem is not a street issue</strong>, or is <strong>not
+ suitable for publication on the site</strong>, then FixMyStreet isn't the
+ right place for it. You should find contact details on your council's own
+ website.
+ </p>
+ [% ELSIF dest == 'update' %]
+ <p>
+ FixMyStreet is great for reporting problems, but we don't fix them - your
+ council oversees that.
+ </p>
+
+ <p>
+ <strong>If you'd like to chase your report</strong>, please reply directly
+ to any response - or auto-reply - that your council sent you. Check that
+ it has your council's email address on it so that it goes to the right place.
+ </p>
+
+ <p>
+ It's a good idea to include the URL [web address] of your original FixMyStreet
+ report.
+ </p>
+
+ <p>
+ <strong>If you're not having any luck getting your community problems fixed</strong>,
+ you could try contacting your local councillor, using another useful mySociety site:
+ <a href="https://www.writetothem.com/">https://www.writetothem.com/</a>.
+ </p>
+
+ [% END %]
+ [% END %]
+
+ <div class="checkbox-group">
+ <input name="dest" id="dest_help" type="radio" value="help" class="required"[% IF dest AND dest == 'help' %] checked[% END %]>
+ <label class="inline" for="dest_help">I need help using the site</label>
+ </div>
+
+ <div class="checkbox-group">
+ <input name="dest" id="dest_feeback" type="radio" value="feeback" class="required"[% IF dest AND dest == 'feeback' %] checked[% END %]>
+ <label class="inline" for="dest_feeback">I have feedback about the site</label>
+ </div>
+
+ <div class="checkbox-group">
+ <input name="dest" id="dest_from_council" type="radio" value="from_council" class="required"[% IF dest AND dest == 'from_council' %] checked[% END %]>
+ <label class="inline" for="dest_from_council">I am from a council and I have a question for the FixMyStreet team</label>
+ </div>
+
+ <div class="checkbox-group">
+ <input name="dest" id="dest_council" type="radio" value="council" class="required"[% IF dest AND dest == 'council' %] checked[% END %]>
+ <label class="inline" for="dest_council">I want to report a street problem</label>
+ </div>
+
+ <div class="checkbox-group">
+ <input name="dest" id="dest_update" type="radio" value="update"[% IF dest AND dest == 'update' %] checked[% END %]>
+ <label class="inline" for="dest_update">My street problem hasn't been fixed</label>
+ </div>
+[% END %]