File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 109109 <% end %>
110110 <% if form . enable_turnstile? %>
111111 < div class ="margin-top-2 ">
112- < div class ="cf-turnstile " data-sitekey ="<%= ENV . fetch ( "TURNSTILE_SITE_KEY" , nil ) %> " data-callback =" onTurnstileSuccess " > </ div >
112+ < div class ="cf-turnstile " data-sitekey ="<%= ENV . fetch ( "TURNSTILE_SITE_KEY" , nil ) %> "> </ div >
113113 <%= hidden_field_tag "cf-turnstile-response" , nil %>
114114 </ div >
115115 <% end %>
131131 autocomplete ="off ">
132132 </ div >
133133</ form >
134-
135- <% if form . enable_turnstile? %>
136- < script >
137- function onTurnstileSuccess ( token ) {
138- document . querySelector ( "input[name='cf-turnstile-response']" ) . value = token ;
139- }
140- </ script >
141-
142- < script src ="https://challenges.cloudflare.com/turnstile/v0/api.js " async defer > </ script >
143- <% end %>
Original file line number Diff line number Diff line change @@ -38,6 +38,9 @@ function FBAform(d, N) {
3838 if ( this . options . formSpecificScript ) {
3939 this . options . formSpecificScript ( ) ;
4040 }
41+ < % if form . enable_turnstile ? % >
42+ this . loadTurnstile ( )
43+ < % end % >
4144 d . dispatchEvent ( new CustomEvent ( 'onTouchpointsFormLoaded' , {
4245 detail : {
4346 formComponent : this
@@ -642,6 +645,18 @@ function FBAform(d, N) {
642645 modalId: function() {
643646 return ` fba - modal - $ { this . options . formId } `;
644647 },
648+ <% if form.enable_turnstile? %>
649+ loadTurnstile: function() {
650+ let script = document.createElement("script");
651+ script.src = "https://challenges.cloudflare.com/turnstile/v0/api.js";
652+ script.async = true;
653+ script.defer = true;
654+ script.onload = function() {
655+ document.querySelector("input[name='cf-turnstile-response']").value = token;
656+ };
657+ document.head.appendChild(script);
658+ },
659+ <% end %>
645660 };
646661};
647662
You can’t perform that action at this time.
0 commit comments