1515 form . addEventListener ( 'submit' , function ( e ) {
1616 e . preventDefault ( ) ;
1717
18+ var formData = new FormData ( form ) ;
19+
20+ var hCaptchaResponse = formData . get ( 'h-captcha-response' ) ;
21+ if ( ! hCaptchaResponse ) {
22+ showStatus ( 'error' , 'Please complete the CAPTCHA spam check before sending.' ) ;
23+ return ;
24+ }
25+
1826 btnText . style . display = 'none' ;
1927 btnLoading . style . display = 'inline' ;
2028 submitBtn . disabled = true ;
2129
22- var formData = new FormData ( form ) ;
23-
2430 var primaryData = new FormData ( ) ;
2531 for ( var pair of formData . entries ( ) ) {
2632 primaryData . append ( pair [ 0 ] , pair [ 1 ] ) ;
3339 headers : { 'Accept' : 'application/json' }
3440 } )
3541 . then ( function ( response ) {
36- if ( response . ok ) {
42+ return response . json ( ) ;
43+ } )
44+ . then ( function ( data ) {
45+ if ( data && data . success ) {
3746 showStatus ( 'success' , 'Thank you! Your message has been sent successfully.' ) ;
3847 form . reset ( ) ;
39- return ;
48+ } else {
49+ console . warn ( 'Web3Forms failed. Falling back to Formspree...' ) ;
50+ return sendFormspree ( formData ) ;
4051 }
41- console . warn ( 'Web3Forms failed. Falling back to Formspree...' ) ;
42- return sendFormspree ( formData ) ;
4352 } )
4453 . catch ( function ( ) {
4554 console . warn ( 'Web3Forms network error. Falling back to Formspree...' ) ;
5362 } ) ;
5463
5564 function sendFormspree ( formData ) {
65+ formData . delete ( 'h-captcha-response' ) ;
66+ formData . delete ( 'g-recaptcha-response' ) ;
67+
5668 return fetch ( FORMSPREE_URL , {
5769 method : 'POST' ,
5870 body : formData ,
89101 } , 400 ) ;
90102 } , 6000 ) ;
91103 }
92- } ) ( ) ;
104+ } ) ( ) ;
0 commit comments