@@ -82,13 +82,7 @@ class ReCaptcha extends InputWidget
82
82
/** @var array Additional html widget options, such as `class`. */
83
83
public $ widgetOptions = [];
84
84
85
- public function init ()
86
- {
87
- parent ::init ();
88
-
89
- $ view = $ this ->view ;
90
- $ view ->registerJs ($ this ->render ('onload ' ), $ view ::POS_BEGIN );
91
- }
85
+ protected static $ firstWidget = true ;
92
86
93
87
public function run ()
94
88
{
@@ -102,17 +96,22 @@ public function run()
102
96
}
103
97
}
104
98
105
- $ arguments = http_build_query ([
106
- 'hl ' => $ this ->getLanguageSuffix (),
107
- 'render ' => 'explicit ' ,
108
- 'onload ' => 'recaptchaOnloadCallback ' ,
109
- ]);
110
-
111
- $ view = $ this ->view ;
112
- $ view ->registerJsFile (
113
- self ::JS_API_URL . '? ' . $ arguments ,
114
- ['position ' => $ view ::POS_END , 'async ' => true , 'defer ' => true ]
115
- );
99
+ if (self ::$ firstWidget ) {
100
+ $ view = $ this ->view ;
101
+ $ arguments = http_build_query ([
102
+ 'hl ' => $ this ->getLanguageSuffix (),
103
+ 'render ' => 'explicit ' ,
104
+ 'onload ' => 'recaptchaOnloadCallback ' ,
105
+ ]);
106
+ $ view ->registerJsFile (
107
+ self ::JS_API_URL . '? ' . $ arguments ,
108
+ ['position ' => $ view ::POS_END , 'async ' => true , 'defer ' => true ]
109
+ );
110
+
111
+ $ view ->registerJs ($ this ->render ('onload ' ), $ view ::POS_BEGIN );
112
+
113
+ self ::$ firstWidget = false ;
114
+ }
116
115
117
116
$ this ->customFieldPrepare ();
118
117
echo Html::tag ('div ' , '' , $ this ->buildDivOptions ());
0 commit comments