File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ < form id ="contact-form ">
2
+ < input type ="text " name ="name " placeholder ="Your Name " required /> < br />
3
+ < input type ="email " name ="email " placeholder ="Your Email " required /> < br />
4
+ < textarea name ="message " placeholder ="Your Message " required > </ textarea > < br />
5
+ < button type ="submit "> Send</ button >
6
+ </ form >
7
+
8
+ < script >
9
+ const form = document . getElementById ( "contact-form" ) ;
10
+ form . addEventListener ( "submit" , async ( e ) => {
11
+ e . preventDefault ( ) ;
12
+ const formData = new FormData ( form ) ;
13
+ const data = Object . fromEntries ( formData . entries ( ) ) ;
14
+
15
+ const response = await fetch ( "YOUR_WEB_APP_URL" , {
16
+ method : "POST" ,
17
+ body : JSON . stringify ( data ) ,
18
+ headers : {
19
+ "Content-Type" : "application/json" ,
20
+ } ,
21
+ } ) ;
22
+
23
+ if ( response . ok ) {
24
+ alert ( "Message sent successfully!" ) ;
25
+ form . reset ( ) ;
26
+ } else {
27
+ alert ( "There was a problem sending your message." ) ;
28
+ }
29
+ } ) ;
30
+ </ script >
You can’t perform that action at this time.
0 commit comments