11<?php
2+
23/**
34 * Copyright (c) 2017 - present
45 * LaravelGoogleRecaptcha - ReCaptchaBuilderV2.php
2021class ReCaptchaBuilderV2 extends ReCaptchaBuilder
2122{
2223
24+ protected static $ allowed_data_attribute = [
25+ "theme " ,
26+ "size " ,
27+ "tabindex " ,
28+ "callback " ,
29+ "cexpired-allback " ,
30+ "error-callback " ,
31+ ];
32+
2333 /**
2434 * ReCaptchaBuilderV2 constructor.
2535 *
@@ -35,13 +45,15 @@ public function __construct(string $api_site_key, string $api_secret_key)
3545 /**
3646 * Write ReCAPTCHA HTML tag in your FORM
3747 * Insert before </form> tag
48+ *
49+ * @param null|array $attributes
3850 * @return string
3951 */
40- public function htmlFormSnippet (): string
52+ public function htmlFormSnippet (? array $ attributes = [] ): string
4153 {
4254
4355 $ data_attributes = [];
44- $ config_data_attributes = $ this ->getTagAttributes ();
56+ $ config_data_attributes = array_merge ( $ this ->getTagAttributes (), self :: cleanAttributes ( $ attributes ) );
4557
4658 foreach ($ config_data_attributes as $ k => $ v ) {
4759 if ($ v ) {
@@ -93,4 +105,16 @@ public function getOnLoadCallback(): string
93105 return "<script>var biscolabOnloadCallback = function() {grecaptcha.render('recaptcha-element', " . json_encode ($ attributes ) . ");};</script> " ;
94106 }
95107
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