-
Notifications
You must be signed in to change notification settings - Fork 10
/
new.html.erb
183 lines (166 loc) · 6.69 KB
/
new.html.erb
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<%
ga4_english_strings = {
page_title: t("controllers.contact.govuk.contact_govuk.title", locale: :en),
questions: {
link: t("controllers.contact.govuk.contact_govuk.questions.link", locale: :en),
textdetails: t("controllers.contact.govuk.contact_govuk.questions.textdetails", locale: :en),
contact: t("controllers.contact.govuk.contact_govuk.questions.contact", locale: :en),
},
submit_text: t("controllers.contact.govuk.contact_govuk.submit_text", locale: :en).downcase
}
ga4_form_tracker_json = {
event_name: "form_response",
type: "contact",
section: ga4_english_strings[:questions][:link],
action: ga4_english_strings[:submit_text],
tool_name: ga4_english_strings[:page_title]
}.to_json
%>
<% content_for :title do t("controllers.contact.govuk.contact_govuk.title") end %>
<%= form_for :contact, url: contact_govuk_path, as: :post, authenticity_token: false, html: { class: "contact-form", data: { module: "ga4-form-tracker", ga4_form: ga4_form_tracker_json } } do |f| %>
<%= hidden_field_tag 'contact[url]', Plek.new.website_root + contact_govuk_path %>
<p class="govuk-body">This form is for issues to do with the GOV.UK website.</p>
<p class="govuk-body">You can use it to ask a question, report a problem or suggest an improvement to the GOV.UK team.</p>
<p class="govuk-body">We can’t reply to you with advice. We don’t have access to information about you held by government departments.</p>
<p class="govuk-body">If you have a question about a government service or policy, check the <a class="govuk-link" href="/help">help pages</a> or contact the <a class="govuk-link" href="/government/organisations">government department</a> directly.</p>
<%= render partial: "shared/spam_honeypot", locals: { form_name: 'contact' } %>
<% if @errors %>
<%
# Each key in the @errors hash is the id of the corresponding question.
# Therefore we can map this key to our ga4_english_strings[:questions] hash to get the question title of each error.
ga4_erroring_sections = @errors.keys.map do |error_key|
if error_key.to_s == "name" || error_key.to_s == "email" # Both errors use the same question title.
ga4_english_strings[:questions][:contact]
else
ga4_english_strings[:questions][error_key]
end
end
ga4_erroring_sections = ga4_erroring_sections.join(', ')
ga4_auto_tracker_json = {
event_name: 'form_error',
type: 'contact',
action: 'error',
text: @errors.values.map { | error_hash | error_hash.first }.join(', '),
section: ga4_erroring_sections,
tool_name: ga4_english_strings[:page_title]
}.to_json
%>
<div data-module="ga4-auto-tracker" data-ga4-auto="<%= ga4_auto_tracker_json %>">
<%= render "govuk_publishing_components/components/error_summary", {
id: "error-summary",
title: "Please check the form",
# app adds a spam protection giraffe error,
# which we do not want to display in the error summary
# so we filter it out
items: @errors.keys.reject { |key| key == :giraffe }.map do |key|
{
text: @errors[key].first,
href: "##{key.to_s}"
}
end
} %>
</div>
<% end %>
<%
value = @old ? @old[:link] : ''
if @errors && @errors[:link]
linkerror = @errors[:link].first
end
%>
<% conditional = capture do %>
<%= render "govuk_publishing_components/components/input", {
label: {
text: "Enter URL or name of page"
},
name: "contact[link]",
id: "link",
value: value,
error_message: linkerror,
data: { ga4_form_include_input: "" }
} %>
<% end %>
<%= render "govuk_publishing_components/components/radio", {
name: "contact[location]",
heading: t("controllers.contact.govuk.contact_govuk.questions.link"),
heading_size: "m",
heading_level: 0,
id_prefix: "location",
items: [
{
value: "all",
text: "The whole site",
checked: @old ? (@old[:location] == "all" ? true : false ) : true,
},
{
value: "specific",
text: "A specific page",
checked: @old ? (@old[:location] == "specific" ? true : false ) : false,
conditional: conditional
}
]
} %>
<%
if @errors && @errors[:textdetails]
textdetailserror = @errors[:textdetails].first
end
%>
<% hint = capture do %>
<p>For example if you were searching for something, what did you type into the search box?</p>
<%= render "govuk_publishing_components/components/warning_text", {
text: "Don’t include personal or financial information, for example your National Insurance number or credit card details."
} %>
<% end %>
<%= render "govuk_publishing_components/components/character_count", {
textarea: {
label: {
text: t("controllers.contact.govuk.contact_govuk.questions.textdetails"),
heading_size: "m"
},
name: "contact[textdetails]",
value: @old ? @old[:textdetails] : '',
hint: hint,
error_message: textdetailserror
},
id: "textdetails",
maxlength: 1200
} %>
<%= render "govuk_publishing_components/components/fieldset", {
legend_text: t("controllers.contact.govuk.contact_govuk.questions.contact"),
heading_size: "m"
} do %>
<p class="govuk-body">If you'd like us to get back to you, please leave your details below.</p>
<%
if @errors && @errors[:name]
name_error = @errors[:name].first
end
%>
<%= render "govuk_publishing_components/components/input", {
label: {
text: "Your name"
},
name: "contact[name]",
id: "name",
autocomplete: "name",
value: @old ? @old[:name] : '',
error_message: name_error
} %>
<%
if @errors && @errors[:email]
email_error = @errors[:email].first
end
%>
<%= render "govuk_publishing_components/components/input", {
label: {
text: "Your email address"
},
hint: "We'll only use this to reply to your message.",
name: "contact[email]",
type: "email",
id: "email",
autocomplete: "email",
value: @old ? @old[:email] : '',
error_message: email_error
} %>
<% end %>
<%= render "govuk_publishing_components/components/button", text: t("controllers.contact.govuk.contact_govuk.submit_text"), margin_bottom: true %>
<% end %>