@@ -117,24 +117,63 @@ document.addEventListener('click', (e) => {
117117} ) ;
118118
119119// Simple Form Submission Handling
120+ // Form Submission Handling
121+ const FORMEASY_URL = "https://script.google.com/macros/s/AKfycbzYVsGnC2GBToA51_39F9Aiu409KRAZQhsaLQgR9dISVteOd2MQJ1_kqQP6OiGjsYaW/exec" ; // TODO: Replace with your actual Formeasy/Google Script URL
122+
120123const enquiryForm = document . getElementById ( 'enquiryForm' ) ;
121124if ( enquiryForm ) {
122- enquiryForm . addEventListener ( 'submit' , ( e ) => {
125+ enquiryForm . addEventListener ( 'submit' , async ( e ) => {
123126 e . preventDefault ( ) ;
124127
125- // Show success message (demo)
126128 const btn = enquiryForm . querySelector ( 'button' ) ;
127129 const originalText = btn . textContent ;
128130
129- btn . textContent = 'Enquiry Sent Successfully! ✓' ;
130- btn . style . background = '#28a745' ;
131+ // Show loading state
132+ btn . textContent = 'Sending...' ;
133+ btn . disabled = true ;
134+
135+ try {
136+ const formData = new FormData ( enquiryForm ) ;
137+ const data = Object . fromEntries ( formData ) ;
138+
139+ const response = await fetch ( FORMEASY_URL , {
140+ method : 'POST' ,
141+ headers : {
142+ 'Content-Type' : 'text/plain;charset=utf-8' ,
143+ } ,
144+ body : JSON . stringify ( data )
145+ } ) ;
146+
147+ if ( ! response . ok ) {
148+ throw new Error ( 'Network response was not ok' ) ;
149+ }
150+
151+
152+ // Success
153+ btn . textContent = 'Enquiry Sent Successfully! ✓' ;
154+ btn . style . background = '#28a745' ;
155+
156+ enquiryForm . reset ( ) ;
131157
132- enquiryForm . reset ( ) ;
158+ setTimeout ( ( ) => {
159+ btn . textContent = originalText ;
160+ btn . style . background = '' ;
161+ btn . disabled = false ;
162+ } , 3000 ) ;
133163
134- setTimeout ( ( ) => {
135- btn . textContent = originalText ;
136- btn . style . background = '' ;
137- } , 3000 ) ;
164+ } catch ( error ) {
165+ console . error ( 'Error submitting form:' , error ) ;
166+
167+ // Error feedback
168+ btn . textContent = 'Error Sending. Try Again.' ;
169+ btn . style . background = '#dc3545' ;
170+
171+ setTimeout ( ( ) => {
172+ btn . textContent = originalText ;
173+ btn . style . background = '' ;
174+ btn . disabled = false ;
175+ } , 3000 ) ;
176+ }
138177 } ) ;
139178}
140179
0 commit comments