Dear community,
I need your help for debugging a form issue that I have with my website. The form I implemented used to work well until June 15th, which is the last time I received a form submission.
I am using Formik, here is the component:
const ContactForm = () => {
const { t, i18n } = useTranslation(["common", "contact"])
const locale = i18n.language
const encode = data => {
return Object.keys(data)
.map(key => encodeURIComponent(key) + "=" + encodeURIComponent(data[key]))
.join("&")
}
return (
<Formik
initialValues={{
firstName: "",
lastName: "",
email: "",
message: "",
}}
validationSchema={Yup.object({
firstName: Yup.string()
.max(15, t("contact:validation.firstname.max"))
.required(t("contact:validation.firstname.required")),
lastName: Yup.string()
.max(20, t("contact:validation.lastname.max"))
.required(t("contact:validation.lastname.required")),
email: Yup.string()
.email(t("contact:validation.email.isEmail"))
.required(t("contact:validation.email.required")),
message: Yup.string().required(
t("contact:validation.message.required")
),
optin: Yup.boolean(),
})}
onSubmit={async (values, { setSubmitting }) => {
if (values.optin === true) {
await addToMailchimp(values.email)
}
console.log(values)
setSubmitting(false)
fetch("/", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: encode({ "form-name": "contact", ...values }),
})
.then(() => navigate(`/${locale}/${t("common:slugs.success")}`))
.catch(error => alert(t("contact:submit.error")))
}}
>
<StyledForm
name="contact"
method="post"
data-netlify="true"
data-netlify-honeypot="bot-field"
>
{/* Hidden inputs for netlify deploy */}
<input type="hidden" name="form-name" value="contact" />
<input type="hidden" name="bot-field" />
<StyledLabel htmlFor="firstName">
{t("contact:form.labels.firstname")}
</StyledLabel>
<StyledField
name="firstName"
type="text"
placeholder={t("contact:form.placeholders.firstname")}
/>
<StyledErrorMessage name="firstName" component="span" />
<StyledLabel htmlFor="lastName">
{t("contact:form.labels.lastname")}
</StyledLabel>
<StyledField
name="lastName"
type="text"
placeholder={t("contact:form.placeholders.lastname")}
/>
<StyledErrorMessage name="lastName" component="span" />
<StyledLabel htmlFor="email">
{t("contact:form.labels.email")}
</StyledLabel>
<StyledField
name="email"
type="email"
placeholder={t("contact:form.placeholders.email")}
/>
<StyledErrorMessage name="email" component="span" />
<StyledLabel htmlFor="message">
{t("contact:form.labels.message")}
</StyledLabel>
<StyledField
name="message"
component="textarea"
rows={8}
placeholder={t("contact:form.placeholders.message")}
/>
<StyledErrorMessage name="message" component="span" />
<Optin>
<Field name="optin" type="checkbox" rows={8} />
<StyledLabel htmlFor="optin">
{t("contact:form.labels.newsletter")}
</StyledLabel>
<StyledErrorMessage name="optin" component="span" />
</Optin>
<PrimaryButton type="submit"> {t("contact:form.button")}</PrimaryButton>
</StyledForm>
</Formik>
)
}
This exact same code use to work properly with form submissions, and there is no error message when form is submitted by the user.
However, I receive spammy emails, last received was 9 days ago.
I would be grateful if someone could help me find the reason for this issue!
Website info:
- netlify site name:
https://la-perle-events.netlify.app/
Thanks