File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed
Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ <h1 class="title">Feel the rhythm.</h1>
3838 Join the waitlist!
3939 </ button >
4040 </ form >
41+ < script src ="waitlist.js "> </ script >
4142 </ div >
4243 </ div >
4344 </ div >
Original file line number Diff line number Diff line change 1+ document . getElementById ( 'waitlist-form' ) . addEventListener ( 'submit' , function ( e ) {
2+ e . preventDefault ( ) ;
3+
4+ const form = e . target ;
5+ const formData = new FormData ( form ) ;
6+
7+ fetch ( form . action , {
8+ method : form . method ,
9+ body : formData ,
10+ headers : {
11+ 'Accept' : 'application/json'
12+ }
13+ } ) . then ( response => {
14+ if ( response . ok ) {
15+ form . reset ( ) ;
16+ alert ( 'Thanks for joining the waitlist!' ) ;
17+ } else {
18+ response . json ( ) . then ( data => {
19+ if ( Object . hasOwn ( data , 'errors' ) ) {
20+ alert ( data [ "errors" ] . map ( error => error [ "message" ] ) . join ( ", " ) ) ;
21+ } else {
22+ alert ( 'Oops! There was a problem submitting your form.' ) ;
23+ }
24+ } ) ;
25+ }
26+ } ) . catch ( error => {
27+ alert ( 'Oops! There was a problem submitting your form.' ) ;
28+ } ) ;
29+ } ) ;
You can’t perform that action at this time.
0 commit comments