-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (47 loc) · 1.74 KB
/
script.js
File metadata and controls
56 lines (47 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
document.addEventListener("DOMContentLoaded", function () {
const contactForm = document.getElementById("contact-form");
contactForm.addEventListener("submit", function (e) {
e.preventDefault();
// Collect form data
const name = document.getElementById("name").value;
const email = document.getElementById("email").value;
const mobile = document.getElementById("mobile").value;
// Create a JSON object with the form data
const formData = {
name: name,
email: email,
mobile: mobile,
};
// Send data to Google Sheets (you would need to implement this)
// Send data to the specified API
sendDataToAPI(formData);
});
});
// Function to send data to the API
function sendDataToAPI(formData) {
// Define the API endpoint URL
const apiUrl = "https://api.propacity.in/api/v1/webhooks/integration/61cf0d44-1ede-4dfa-b3ce-930072581261/insertLead";
// Send a POST request to the API
fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
})
.then(response => {
if (response.ok) {
return response.json(); // If the response is successful, parse the JSON response
} else {
throw new Error('Failed to send data to the API');
}
})
.then(data => {
console.log('Data sent successfully:', data);
// You can handle the API response here
})
.catch(error => {
console.error('Error:', error);
// Handle errors here
});
}