@@ -152,34 +152,44 @@ function biscolabLaravelReCaptcha(token) {
152
152
</script> ' ;
153
153
}
154
154
elseif ($ this ->version == 'v3 ' ) {
155
+
155
156
$ action = array_get ($ configuration , 'action ' , 'homepage ' );
156
- $ js_then_callback = array_get ($ configuration , 'callback_then ' , '' );
157
- $ js_callback_catch = array_get ($ configuration , 'callback_catch ' , '' );
158
157
159
- $ js_then_callback = ($ js_then_callback ) ? "{$ js_then_callback }(response) " : '' ;
160
- $ js_callback_catch = ($ js_callback_catch ) ? "{$ js_callback_catch }(err) " : '' ;
158
+ $ js_custom_validation = array_get ($ configuration , 'custom_validation ' , '' );
159
+
160
+ // Check if set custom_validation. That function will override default fetch validation function
161
+ if ($ js_custom_validation ) {
162
+
163
+ $ validate_function = ($ js_custom_validation ) ? "{$ js_custom_validation }(token); " : '' ;
164
+ }
165
+ else {
166
+
167
+ $ js_then_callback = array_get ($ configuration , 'callback_then ' , '' );
168
+ $ js_callback_catch = array_get ($ configuration , 'callback_catch ' , '' );
169
+
170
+ $ js_then_callback = ($ js_then_callback ) ? "{$ js_then_callback }(response) " : '' ;
171
+ $ js_callback_catch = ($ js_callback_catch ) ? "{$ js_callback_catch }(err) " : '' ;
172
+
173
+ $ validate_function = "
174
+ fetch('/ " . config ('recaptcha.default_validation_route ' , 'biscolab-recaptcha/validate ' ) . "? " . config ('recaptcha.default_token_parameter_name ' , 'token ' ) . "=' + token, {
175
+ headers: {
176
+ \"X-Requested-With \": \"XMLHttpRequest \",
177
+ \"X-CSRF-TOKEN \": csrfToken.content
178
+ }
179
+ })
180
+ .then(function(response) {
181
+ {$ js_then_callback }
182
+ })
183
+ .catch(function(err) {
184
+ {$ js_callback_catch }
185
+ }); " ;
186
+ }
161
187
162
188
$ html .= "<script>
163
189
var csrfToken = document.head.querySelector('meta[name= \"csrf-token \"]');
164
190
grecaptcha.ready(function() {
165
191
grecaptcha.execute(' {$ this ->api_site_key }', {action: ' {$ action }'}).then(function(token) {
166
- fetch('/ " . config ('recaptcha.default_validation_route ' , 'biscolab-recaptcha/validate ' ) . "? " . config ('recaptcha.default_token_parameter_name ' , 'token ' ) . "=' + token, {
167
- headers: {
168
- \"X-Requested-With \": \"XMLHttpRequest \",
169
- \"X-CSRF-TOKEN \": csrfToken.content
170
- }
171
- })
172
-
173
- .then(function(response) {
174
- {$ js_then_callback }
175
- // console.log(response.status);
176
- // response.json().then(function(data){
177
- // console.log(data);
178
- // });
179
- })
180
- .catch(function(err) {
181
- {$ js_callback_catch }
182
- });
192
+ {$ validate_function }
183
193
});
184
194
});
185
195
</script> " ;
0 commit comments