I’m using Gatsby and the “react-hook-form” in a contact form, but data-netlify-recaptcha = “true” doesn’t work what can I do to work?
Code:
import React from "react" import { useForm } from "react-hook-form" import * as S from "./styled" const ContactForm = () => { const { register, errors, handleSubmit } = useForm({ mode: "onChange" }); const onSubmit = (data, e) => { console.log(JSON.stringify(data)) e.target.submit() } return( <S.ContactWrapper> <S.ContactForm onSubmit={handleSubmit(onSubmit)} name="contact" method="post" netlify-honeypot="bot-field" data-netlify-recaptcha="true" data-netlify="true"> <S.ContactInput type="hidden" name="bot-field" /> <S.ContactInput type="hidden" name="form-name" value="contact" /> <S.LabelMain for="name"><S.LabelName>Name:</S.LabelName> <S.ContactInput type="text" name="name" id="name" alt="Name" placeholder="Your Name" ref={register({ required: "Required Field", maxLength: { value: 30, message: "Max 30 characters" } })} /> {errors.name && <S.Error>{errors.name.message}</S.Error>} </S.LabelMain> <S.LabelMain for="email"><S.LabelName>Email:</S.LabelName> <S.ContactInput type="email" name="email" id="email" alt="Email" placeholder="Your Email" ref={register({ required: "Required Field", pattern: { value: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/, message: "Invalid E-mail" } })} /> {errors.email && <S.Error>{errors.email.message}</S.Error>} </S.LabelMain> <S.LabelMain for="message"><S.LabelName>Mensagem:</S.LabelName> <S.ContactArea name="message" id="message" rows="5" cols="33" alt="Message" placeholder="Your Message ..." ref={register({ required: "Required Field", maxLength: { value: 180, message: "Max 180 caracters" } })} /> {errors.message && <S.Error>{errors.message.message}</S.Error>} </S.LabelMain> <div data-netlify-recaptcha="true"></div> <S.ContactButtonSend type="submit" aria-label="Send"> <S.IconSend/>Send</S.ContactButtonSend> <S.ContactButtonRest type="reset" aria-label="Reset"><S.IconRest/>Reset</S.ContactButtonRest> </S.ContactForm> </S.ContactWrapper> ) } export default ContactForm
Any help would be greatly appreciated! Thank you.