@@ -17,34 +17,33 @@ googleRecaptchaScript.addEventListener('load', function() {
1717 console . debug ( "Executing Google Recaptcha on action:" , action ) ;
1818 }
1919
20- var form = element . closest ( "form" ) ;
21-
22- if ( form ) {
23- var submitButtons = form . querySelectorAll ( '[type="submit"]' ) ;
24- submitButtons = submitButtons ? submitButtons : [ ] ;
25-
26- for ( var submitButton of submitButtons ) {
27- submitButton . addEventListener ( 'click' , function ( e ) {
28- e . preventDefault ( ) ;
29-
30- grecaptcha . execute ( _config . googleRecaptcha . publicKey , { action : action } ) . then ( function ( token ) {
31- if ( _config . googleRecaptcha . debug ) {
32- console . debug ( "Received response for action:" , action , token ) ;
33- }
34-
35- element . value = token ;
36-
37- var doSubmit = form . dispatchEvent ( new Event ( 'submit' , {
38- cancelable : true
39- } ) ) ;
40-
41- if ( doSubmit ) {
42- form . submit ( ) ;
43- }
44- } ) ;
20+ var submitButtons = element . closest ( 'form' ) . querySelectorAll ( '[type="submit"]' ) ;
21+ submitButtons = submitButtons ? submitButtons : [ ] ;
22+
23+ for ( var submitButton of submitButtons ) {
24+ submitButton . addEventListener ( 'click' , function ( e ) {
25+ e . preventDefault ( ) ;
26+
27+ var form = e . target . closest ( "form" ) ;
28+
29+ grecaptcha . execute ( _config . googleRecaptcha . publicKey , { action : action } ) . then ( function ( token ) {
30+ if ( _config . googleRecaptcha . debug ) {
31+ console . debug ( "Received response for action:" , action , token ) ;
32+ }
33+
34+ form . querySelector ( _config . googleRecaptcha . querySelector ) . value = token ;
35+
36+ var doSubmit = form . dispatchEvent ( new Event ( 'submit' , {
37+ cancelable : true
38+ } ) ) ;
39+
40+ if ( doSubmit ) {
41+ form . submit ( ) ;
42+ }
4543 } ) ;
46- }
44+ } ) ;
4745 }
46+
4847 }
4948 } else if ( _config . googleRecaptcha . debug ) {
5049 console . debug ( "Could not find Google Recaptcha elements for query selector '" + _config . googleRecaptcha . querySelector + "'" ) ;
0 commit comments