Commit d8928221 by Aman

changes in form done

1 parent fba5ef14
......@@ -20,95 +20,128 @@ const CallBackRequest = () => {
// email api
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 = {
mobilenumber: data.Mobile,
email: data.Email,
message: data.AdditionalMessage || "",
name: data.Name,
service: data.service,
source: data.source,
source: data.source || "Home page form",
};
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",
},
};
console.log("Submitting to Zoho:", leadData);
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",
},
const response = await fetch("/api/submitZoho", {
method: "POST",
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");
sendEmaill(data);
reset();
} else {
console.error("Zoho submission failed:", response.status);
}
} catch (error) {
console.error(
"Error submitting to Google Sheet API:",
error.response ? error.response.data : error.message
);
console.error("Error submitting form:", error);
}
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 (
<>
<div className="free-quote-area ptb-100">
......
......@@ -19,109 +19,135 @@ const ContactForm = () => {
// email api
const router = useRouter();
const onSubmit = async (data) => {
const finaldata = new FormData();
const leadData = {
mobilenumber: data.Mobile,
email: data.Email,
message: data.AdditionalMessage || "",
name: data.Name,
company: data.Company,
source: data.source,
};
// const onSubmit = async (data) => {
// const finaldata = new FormData();
// const leadData = {
// mobilenumber: data.Mobile,
// email: data.Email,
// message: data.AdditionalMessage || "",
// name: data.Name,
// company: data.Company,
// source: data.source,
// };
// console.log("data", data);
// // console.log("data", data);
const strapiData = {
data: {
Name: data.Name,
Phone: data.Mobile,
Email: data.Email,
Message: data.AdditionalMessage || "",
Company: data.Company,
Source: data.source,
},
};
// const strapiData = {
// data: {
// Name: data.Name,
// Phone: data.Mobile,
// Email: data.Email,
// Message: data.AdditionalMessage || "",
// Company: data.Company,
// 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));
console.log("formvalue", finaldata);
// console.log(leadData, "form-data");
// await fetch("/api/submitZoho", {
// method: "POST",
// headers: { "Content-Type": "application/json" },
// body: JSON.stringify(leadData),
// });
// strapi
const config = {
headers: {
"Content-Type": "multipart/form-data",
},
};
// try {
// const response = await axios.post(
// `${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/contact-forms`,
// 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", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(leadData),
});
// 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();
// };
try {
const response = await axios.post(
`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/contact-forms`,
strapiData,
config
);
if (response.status === 200) {
console.log("Form submited to strapi");
}
} catch (error) {
console.error(error);
}
const onSubmit = async (data) => {
const leadData = {
mobilenumber: data.Mobile,
email: data.Email,
message: data.AdditionalMessage || "",
name: data.Name,
company: data.Company,
source: data.source,
};
console.log("Submitting to Zoho:", leadData);
try {
const response = await axios.post("/api/googlesheetapi", leadData, {
headers: {
"Content-Type": "application/json",
},
const response = await fetch("/api/submitZoho", {
method: "POST",
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");
sendEmaill(data);
reset();
} else {
console.error("Zoho submission failed:", response.status);
}
} catch (error) {
console.error(
"Error submitting to Google Sheet API:",
error.response ? error.response.data : error.message
);
console.error("Error submitting form:", error);
}
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 (
......@@ -138,8 +164,8 @@ const ContactForm = () => {
<span className="sub-title">SEND MESSAGE</span>
<Heading heading="Write to Us!" />
<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>
<form onSubmit={handleSubmit(onSubmit)}>
......@@ -209,7 +235,10 @@ const ContactForm = () => {
placeholder="Mobile"
className="text-dark form-control"
onInput={(e) => {
e.target.value = e.target.value.replace(/[^0-9]/g, '');
e.target.value = e.target.value.replace(
/[^0-9]/g,
""
);
}}
{...register("Mobile", {
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!