1
1
<?php
2
+
2
3
/**
3
4
* Copyright (c) 2017 - present
4
5
* LaravelGoogleRecaptcha - ReCaptchaBuilderV2.php
20
21
class ReCaptchaBuilderV2 extends ReCaptchaBuilder
21
22
{
22
23
24
+ protected static $ allowed_data_attribute = [
25
+ "theme " ,
26
+ "size " ,
27
+ "tabindex " ,
28
+ "callback " ,
29
+ "cexpired-allback " ,
30
+ "error-callback " ,
31
+ ];
32
+
23
33
/**
24
34
* ReCaptchaBuilderV2 constructor.
25
35
*
@@ -35,13 +45,15 @@ public function __construct(string $api_site_key, string $api_secret_key)
35
45
/**
36
46
* Write ReCAPTCHA HTML tag in your FORM
37
47
* Insert before </form> tag
48
+ *
49
+ * @param null|array $attributes
38
50
* @return string
39
51
*/
40
- public function htmlFormSnippet (): string
52
+ public function htmlFormSnippet (? array $ attributes = [] ): string
41
53
{
42
54
43
55
$ data_attributes = [];
44
- $ config_data_attributes = $ this ->getTagAttributes ();
56
+ $ config_data_attributes = array_merge ( $ this ->getTagAttributes (), self :: cleanAttributes ( $ attributes ) );
45
57
46
58
foreach ($ config_data_attributes as $ k => $ v ) {
47
59
if ($ v ) {
@@ -93,4 +105,16 @@ public function getOnLoadCallback(): string
93
105
return "<script>var biscolabOnloadCallback = function() {grecaptcha.render('recaptcha-element', " . json_encode ($ attributes ) . ");};</script> " ;
94
106
}
95
107
96
- }
108
+ /**
109
+ * Compare given attributes with allowed attributes
110
+ *
111
+ * @param array|null $attributes
112
+ * @return array
113
+ */
114
+ protected static function cleanAttributes (?array $ attributes = []): array
115
+ {
116
+ return array_filter ($ attributes , function ($ k ) {
117
+ return in_array ($ k , self ::$ allowed_data_attribute );
118
+ }, ARRAY_FILTER_USE_KEY );
119
+ }
120
+ }
0 commit comments