You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用React Hook Form对接EmailJS时报第三个参数需为HTML表单元素错误

我尝试使用相关方案修复React Hook Form搭配EmailJs时出现的TypeError: e.preventDefault is not a function报错,但即便完全复用代码也出现了新报错,请问EmailJS近期是否有版本调整?

Error: The 3rd parameter is expected to be the HTML form element

报错截图

恳请大家帮忙排查问题,万分感谢。

已验证可行的解决方案

sendEmail函数实现

const sendEmail = (formData, e) => {
  // Send email
  emailjs.sendForm("YOUR_SERVICE_ID", "YOUR_TEMPLATE_ID", e.target, "YOUR_USER_ID")
    .then((result) => {
        console.log(result.text);
    }, (error) => {
        console.log(error.text);
    });
    reset();
};

基于styled-components的表单代码

<Form onSubmit={handleSubmit(sendEmail)}>
    <FormH1>Register your information</FormH1>
    <FormLabel>Name</FormLabel>
    <FormInput
        {...register("name", {
        required: true,
        maxLength: 20,
        pattern: /^[A-Za-z]+$/i
    })} type="text" name="name"/>
        {errors?.name?.type === "required" && <FormError>This field is required</FormError>}
        {errors?.name?.type === "maxLength" && <FormError>First name cannot exceed 20 characters</FormError>}
        {errors?.name?.type === "pattern" && <FormError>Alphabetical characters only</FormError>}
    <FormLabel>Email</FormLabel>
    <FormInput
        {...register("email", {
        required: true,
        pattern: /\S+@\S+\.\S+/
    })} type="email" name="email"/>
        {errors?.email?.type === "required" && <FormError>This field is required</FormError>}
        {errors?.email?.type === "pattern" && <FormError>Entered value does not match email format</FormError>}
    <FormLabel>ORCID</FormLabel>
    <FormInput {...register("orcid", { 
        required: true,
        minLength: 16, 
        maxLength: 16,
        pattern: /^[0-9\b]+$/
    })} type="number" name="orcid"/>
        {errors?.orcid?.type === "required" && <FormError>This field is required</FormError>}
        {errors?.orcid?.type === "minLength" && <FormError>It must be a number of 16 digits</FormError> }
        {errors?.orcid?.type === "maxLength" && <FormError>It must be a number of 16 digits</FormError> }
        {errors?.orcid?.type === "pattern" && <FormError>Numerical characters only</FormError> }
    <FormButton type="submit"/>
</Form>

内容的提问来源于stack exchange,提问作者Joncarre

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 14:45:01