Skip to content

Commit d9f0070

Browse files
explicitly render turnstile
2 parents 72d5db1 + 222863c commit d9f0070

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

app/views/admin/submissions/show.html.erb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@
184184
<%= h(@submission.referer) %>
185185
</td>
186186
</tr>
187+
<tr>
188+
<td>
189+
Spam prevention mechanism
190+
</td>
191+
<td>
192+
<%= h(@submission.spam_prevention_mechanism) %>
193+
</td>
194+
</tr>
187195
<tr>
188196
<td>
189197
Language

app/views/components/forms/_custom.html.erb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@
107107
<% end %>
108108
</div>
109109
<% end %>
110-
<% if form.enable_turnstile? %>
111-
<div class="margin-top-2">
112-
<div class="cf-turnstile" data-sitekey="<%= ENV.fetch("TURNSTILE_SITE_KEY", nil) %>"></div>
113-
<%= hidden_field_tag "cf-turnstile-response", nil %>
114-
</div>
115-
<% end %>
116110
<%- if section == form.form_sections.last && !form.suppress_submit_button %>
111+
<%- if form.enable_turnstile? %>
112+
<div class="margin-top-2">
113+
<div id="turnstile-container"></div>
114+
<%= hidden_field_tag "cf-turnstile-response", nil %>
115+
</div>
116+
<% end %>
117117
<button type="submit" class="usa-button submit_form_button"><%= t 'form.submit' %></button>
118118
<% end %>
119119
</div>

app/views/components/widget/_fba.js.erb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,19 @@ function FBAform(d, N) {
656656
script.src = "https://challenges.cloudflare.com/turnstile/v0/api.js";
657657
script.async = true;
658658
script.defer = true;
659-
document.head.appendChild(script);
659+
script.onload = this.initTurnstile
660+
if (!window.turnstile) {
661+
document.head.appendChild(script);
662+
}
663+
},
664+
initTurnstile: function() {
665+
turnstile.remove("#turnstile-container");
666+
turnstile.render("#turnstile-container", {
667+
sitekey: "<%= ENV['TURNSTILE_SITE_KEY'] %>",
668+
callback: function (token) {
669+
document.querySelector("input[name='cf-turnstile-response']").value = token;
670+
}
671+
});
660672
},
661673
<% end %>
662674
enableLocalStorage: function() {

0 commit comments

Comments
 (0)