diff --git a/app/_contact-us/form.tsx b/app/_contact-us/form.tsx index 19a402b..51f1dbd 100644 --- a/app/_contact-us/form.tsx +++ b/app/_contact-us/form.tsx @@ -33,10 +33,11 @@ const ContactUsForm = ({ const { register, handleSubmit, - formState: { errors }, + formState: { errors, isValid }, reset, setError, - } = useForm(); + trigger, + } = useForm({ mode: "onChange" }); const onCaptchaVerify = (token: string) => { setHcaptchaToken(token); @@ -47,6 +48,11 @@ const ContactUsForm = ({ }; const onSubmit = async (data: TContactUsForm) => { + const isFormValid = await trigger(); + if (!isFormValid) { + return; + } + if (!hcaptchaToken) { toast.error("Please complete the captcha verification"); return; @@ -124,7 +130,10 @@ const ContactUsForm = ({ />
-
diff --git a/app/_inquires/form.tsx b/app/_inquires/form.tsx index ca5af3e..7bcad38 100644 --- a/app/_inquires/form.tsx +++ b/app/_inquires/form.tsx @@ -32,10 +32,11 @@ const InquiresForm = ({ const { register, handleSubmit, - formState: { errors }, + formState: { errors, isValid }, reset, setError, - } = useForm(); + trigger, + } = useForm({ mode: "onChange" }); const defaultFields = useMemo( () => [ @@ -78,6 +79,11 @@ const InquiresForm = ({ setHcaptchaToken(null); }; const onSubmit = async (data: TInquiresForm) => { + const isFormValid = await trigger(); + if (!isFormValid) { + return; + } + if (!hcaptchaToken) { toast.error("Please complete the captcha verification"); return; @@ -211,7 +217,10 @@ const InquiresForm = ({ />
-