Commit d8928221 by Aman

changes in form done

1 parent fba5ef14
...@@ -20,95 +20,128 @@ const CallBackRequest = () => { ...@@ -20,95 +20,128 @@ const CallBackRequest = () => {
// email api // email api
const router = useRouter(); const router = useRouter();
const onSubmit = async (data) => { // const onSubmit = async (data) => {
// const leadData = {
// mobilenumber: data.Mobile,
// email: data.Email,
// message: data.AdditionalMessage || "",
// name: data.Name,
// service: data.service,
// source: data.source,
// };
// console.log(leadData, "form-data");
// const strapiData = {
// data: {
// Name: data.Name,
// Phone: data.Mobile,
// Email: data.Email,
// Service: data.service,
// Source: data.source,
// },
// };
// console.log("strapiData", strapiData);
// const config = {
// headers: {
// "Content-Type": "multipart/form-data",
// },
// };
// try {
// const response = await axios.post(
// `${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/service-forms`,
// strapiData,
// config
// );
// if (response.status === 200) {
// console.log("Form submited to strapi");
// }
// } catch (error) {
// console.error(error);
// }
// await fetch("/api/submitZoho", {
// method: "POST",
// headers: { "Content-Type": "application/json" },
// body: JSON.stringify(leadData),
// });
// try {
// const response = await axios.post("/api/homegooglesheet", leadData, {
// headers: {
// "Content-Type": "application/json",
// },
// });
// console.log("Google Sheet API response:", response?.data);
// if (response.data.success) {
// router.push("/thank-you");
// sendEmaill(data);
// }
// } catch (error) {
// console.error(
// "Error submitting to Google Sheet API:",
// error.response ? error.response.data : error.message
// );
// }
// reset();
// };
// const sendEmaill = (data) => {
// fetch("/api/sendEmailHome", {
// method: "POST",
// headers: {
// Accept: "application/json, text/plain, */*",
// "Content-Type": "application/json",
// },
// body: JSON.stringify(data),
// })
// .then((response) => {
// console.log("response received", response);
// if (response.status === 200) {
// console.log("response succeeded");
// } else {
// console.log("response failed");
// }
// })
// .catch((error) => {
// console.error(error);
// });
// };
const onSubmit = async (data) => {
const leadData = { const leadData = {
mobilenumber: data.Mobile, mobilenumber: data.Mobile,
email: data.Email, email: data.Email,
message: data.AdditionalMessage || "", message: data.AdditionalMessage || "",
name: data.Name, name: data.Name,
service: data.service, service: data.service,
source: data.source, source: data.source || "Home page form",
}; };
console.log(leadData, "form-data");
const strapiData = { console.log("Submitting to Zoho:", leadData);
data: {
Name: data.Name,
Phone: data.Mobile,
Email: data.Email,
Service: data.service,
Source: data.source,
},
};
console.log("strapiData", strapiData);
const config = {
headers: {
"Content-Type": "multipart/form-data",
},
};
try { try {
const response = await axios.post( const response = await fetch("/api/submitZoho", {
`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/service-forms`, method: "POST",
strapiData, headers: { "Content-Type": "application/json" },
config body: JSON.stringify(leadData),
);
if (response.status === 200) {
console.log("Form submited to strapi");
}
} catch (error) {
console.error(error);
}
await fetch("/api/submitZoho", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(leadData),
});
try {
const response = await axios.post("/api/homegooglesheet", leadData, {
headers: {
"Content-Type": "application/json",
},
}); });
console.log("Google Sheet API response:", response?.data);
if (response.data.success) { if (response.ok) {
console.log("Form submitted successfully to Zoho");
router.push("/thank-you"); router.push("/thank-you");
sendEmaill(data); reset();
} else {
console.error("Zoho submission failed:", response.status);
} }
} catch (error) { } catch (error) {
console.error( console.error("Error submitting form:", error);
"Error submitting to Google Sheet API:",
error.response ? error.response.data : error.message
);
} }
reset();
};
const sendEmaill = (data) => {
fetch("/api/sendEmailHome", {
method: "POST",
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
.then((response) => {
console.log("response received", response);
if (response.status === 200) {
console.log("response succeeded");
} else {
console.log("response failed");
}
})
.catch((error) => {
console.error(error);
});
}; };
return ( return (
<> <>
<div className="free-quote-area ptb-100"> <div className="free-quote-area ptb-100">
......
...@@ -19,109 +19,135 @@ const ContactForm = () => { ...@@ -19,109 +19,135 @@ const ContactForm = () => {
// email api // email api
const router = useRouter(); const router = useRouter();
const onSubmit = async (data) => { // const onSubmit = async (data) => {
const finaldata = new FormData(); // const finaldata = new FormData();
const leadData = { // const leadData = {
mobilenumber: data.Mobile, // mobilenumber: data.Mobile,
email: data.Email, // email: data.Email,
message: data.AdditionalMessage || "", // message: data.AdditionalMessage || "",
name: data.Name, // name: data.Name,
company: data.Company, // company: data.Company,
source: data.source, // source: data.source,
}; // };
// console.log("data", data); // // console.log("data", data);
const strapiData = { // const strapiData = {
data: { // data: {
Name: data.Name, // Name: data.Name,
Phone: data.Mobile, // Phone: data.Mobile,
Email: data.Email, // Email: data.Email,
Message: data.AdditionalMessage || "", // Message: data.AdditionalMessage || "",
Company: data.Company, // Company: data.Company,
Source: data.source, // Source: data.source,
}, // },
}; // };
// console.log("strapiData", strapiData);
// finaldata.append("data", JSON.stringify(strapiData));
// console.log("formvalue", finaldata);
// // console.log(leadData, "form-data");
console.log("strapiData", strapiData); // // strapi
// const config = {
// headers: {
// "Content-Type": "multipart/form-data",
// },
// };
finaldata.append("data", JSON.stringify(strapiData)); // await fetch("/api/submitZoho", {
console.log("formvalue", finaldata); // method: "POST",
// console.log(leadData, "form-data"); // headers: { "Content-Type": "application/json" },
// body: JSON.stringify(leadData),
// });
// strapi // try {
const config = { // const response = await axios.post(
headers: { // `${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/contact-forms`,
"Content-Type": "multipart/form-data", // strapiData,
}, // config
}; // );
// if (response.status === 200) {
// console.log("Form submited to strapi");
// }
// } catch (error) {
// console.error(error);
// }
// try {
// const response = await axios.post("/api/googlesheetapi", leadData, {
// headers: {
// "Content-Type": "application/json",
// },
// });
// console.log("Google Sheet API response:", response?.data);
// if (response.data.success) {
// router.push("/thank-you");
// sendEmaill(data);
// }
// } catch (error) {
// console.error(
// "Error submitting to Google Sheet API:",
// error.response ? error.response.data : error.message
// );
// }
await fetch("/api/submitZoho", { // const sendEmaill = (data) => {
method: "POST", // fetch("/api/sendEmail", {
headers: { "Content-Type": "application/json" }, // method: "POST",
body: JSON.stringify(leadData), // headers: {
}); // Accept: "application/json, text/plain, */*",
// "Content-Type": "application/json",
// },
// body: JSON.stringify(data),
// })
// .then((response) => {
// console.log("response received", response);
// if (response.status === 200) {
// console.log("response succeeded");
// } else {
// console.log("response failed");
// }
// })
// .catch((error) => {
// console.error(error);
// });
// };
// sendEmaill(data);
// reset();
// };
try { const onSubmit = async (data) => {
const response = await axios.post( const leadData = {
`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/contact-forms`, mobilenumber: data.Mobile,
strapiData, email: data.Email,
config message: data.AdditionalMessage || "",
); name: data.Name,
if (response.status === 200) { company: data.Company,
console.log("Form submited to strapi"); source: data.source,
} };
} catch (error) {
console.error(error); console.log("Submitting to Zoho:", leadData);
}
try { try {
const response = await axios.post("/api/googlesheetapi", leadData, { const response = await fetch("/api/submitZoho", {
headers: { method: "POST",
"Content-Type": "application/json", headers: { "Content-Type": "application/json" },
}, body: JSON.stringify(leadData),
}); });
console.log("Google Sheet API response:", response?.data);
if (response.data.success) { if (response.ok) {
console.log("Form submitted successfully to Zoho");
router.push("/thank-you"); router.push("/thank-you");
sendEmaill(data); reset();
} else {
console.error("Zoho submission failed:", response.status);
} }
} catch (error) { } catch (error) {
console.error( console.error("Error submitting form:", error);
"Error submitting to Google Sheet API:",
error.response ? error.response.data : error.message
);
} }
const sendEmaill = (data) => {
fetch("/api/sendEmail", {
method: "POST",
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
.then((response) => {
console.log("response received", response);
if (response.status === 200) {
console.log("response succeeded");
} else {
console.log("response failed");
}
})
.catch((error) => {
console.error(error);
});
};
sendEmaill(data);
reset();
}; };
return ( return (
...@@ -138,8 +164,8 @@ const ContactForm = () => { ...@@ -138,8 +164,8 @@ const ContactForm = () => {
<span className="sub-title">SEND MESSAGE</span> <span className="sub-title">SEND MESSAGE</span>
<Heading heading="Write to Us!" /> <Heading heading="Write to Us!" />
<p> <p>
Lets connect to explore how Adviths customized solutions can drive your business forward. Lets connect to explore how Adviths customized solutions can
drive your business forward.
</p> </p>
<form onSubmit={handleSubmit(onSubmit)}> <form onSubmit={handleSubmit(onSubmit)}>
...@@ -209,7 +235,10 @@ const ContactForm = () => { ...@@ -209,7 +235,10 @@ const ContactForm = () => {
placeholder="Mobile" placeholder="Mobile"
className="text-dark form-control" className="text-dark form-control"
onInput={(e) => { onInput={(e) => {
e.target.value = e.target.value.replace(/[^0-9]/g, ''); e.target.value = e.target.value.replace(
/[^0-9]/g,
""
);
}} }}
{...register("Mobile", { {...register("Mobile", {
required: "Enter Your Mobile Number", required: "Enter Your Mobile Number",
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!