File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -119,5 +119,37 @@ <h2>Contact</h2>
119119 © 2025 Your Name | Built with ❤️ | Hosted on GitHub Pages
120120 </ footer >
121121
122+ < script >
123+ const form = document . querySelector ( 'form' ) ;
124+ form . addEventListener ( 'submit' , async ( e ) => {
125+ e . preventDefault ( ) ;
126+
127+ const data = {
128+ name : form . elements [ 0 ] . value ,
129+ email : form . elements [ 1 ] . value ,
130+ phone : form . elements [ 2 ] . value ,
131+ subject : form . elements [ 3 ] . value ,
132+ message : form . elements [ 4 ] . value ,
133+ } ;
134+
135+ try {
136+ const response = await fetch ( 'https://your-backend-url.com/contact' , {
137+ method : 'POST' ,
138+ headers : { 'Content-Type' : 'application/json' } ,
139+ body : JSON . stringify ( data )
140+ } ) ;
141+
142+ if ( response . ok ) {
143+ alert ( 'Message sent successfully!' ) ;
144+ form . reset ( ) ;
145+ } else {
146+ alert ( 'Failed to send message.' ) ;
147+ }
148+ } catch ( error ) {
149+ alert ( 'Error sending message.' ) ;
150+ }
151+ } ) ;
152+ </ script >
153+
122154</ body >
123155</ html >
You can’t perform that action at this time.
0 commit comments