Issue with Gatsby Netlify Form not receiving Submissions - reactjs

I got the Netlify form working and accepting submissions but once I started setting up AJAX according to https://docs.netlify.com/forms/setup/, I can't figure out why submissions aren't being received.
Things I've tried:
Removing Hidden "form-name" input
Removing Recaptcha
Running "gatsby clean"
Removing opening Form tag's method attribute (method: "POST")
Removing action attribute from the opening Form tag and setting it directly in handleSubmit:
.then(() => navigate("/thank-you/"))
Any suggestions or fixes are really appreciated!
contact-form.js:
import React, { setState } from "react"
import styled from "styled-components"
import Recaptcha from "react-google-recaptcha"
import { navigate } from "gatsby"
import { Button, Col, Form, Row } from "react-bootstrap"
import { breakpoints } from "../utils/breakpoints"
const RECAPTCHA_KEY = process.env.GATSBY_RECAPTCHA_KEY
export default function ContactForm() {
const [state, setState] = React.useState({})
const recaptchaRef = React.createRef() // new Ref for reCaptcha
const [buttonDisabled, setButtonDisabled] = React.useState(true)
const handleChange = e => {
setState({ ...state, [e.target.name]: e.target.value })
}
const encode = data => {
return Object.keys(data)
.map(key => encodeURIComponent(key) + "=" + encodeURIComponent(data[key]))
.join("&")
}
const handleSubmit = e => {
e.preventDefault()
const form = e.target
const recaptchaValue = recaptchaRef.current.getValue()
fetch("/", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: encode({
"form-name": "contact",
"g-recaptcha-response": recaptchaValue,
...state,
}),
})
.then(() => navigate(form.getAttribute("action")))
.catch(error => alert(error))
}
return (
<Form
name="contact"
method="POST"
netlify
action="/thank-you"
netlify-honeypot="bot-field"
data-netlify-recaptcha="true"
onSubmit={handleSubmit}
>
<Row>
<Col md={12}>
<h3>Message Us</h3>
</Col>
</Row>
<Row>
<Col md={6}>
<Form.Group hidden>
<Form.Label htmlFor="bot-field">
Bot Field: Humans do not fill out!
</Form.Label>
<Form.Control name="bot-field" />
<Form.Control name="form-name" value="contact" />
</Form.Group>
<Form.Group>
<Form.Label htmlFor="first-name">First Name</Form.Label>
<Form.Control
required
size="lg"
type="text"
name="first-name"
onChange={handleChange}
/>
</Form.Group>
</Col>
<Col md={6}>
<Form.Group>
<Form.Label htmlFor="last-name">Last Name</Form.Label>
<Form.Control
required
size="lg"
type="text"
name="last-name"
onChange={handleChange}
/>
</Form.Group>
</Col>
</Row>
<Row>
<Col md={6}>
<Form.Group>
<Form.Label htmlFor="email">Email</Form.Label>
<Form.Control
required
size="lg"
type="email"
name="email"
onChange={handleChange}
/>
</Form.Group>
</Col>
<Col md={6}>
<Form.Group>
<Form.Label htmlFor="phone">Phone (Optional)</Form.Label>
<Form.Control
size="lg"
type="tel"
name="phone"
onChange={handleChange}
/>
</Form.Group>
</Col>
</Row>
<Row>
<Col md={12}>
<Form.Group>
<Form.Label htmlFor="message">Message</Form.Label>
<Form.Control
required
as="textarea"
rows="3"
placeholder="Enter your message here."
name="message"
onChange={handleChange}
/>
</Form.Group>
</Col>
</Row>
<Row>
<Col md={12}>
<FormControls>
<Recaptcha
ref={recaptchaRef}
sitekey={RECAPTCHA_KEY}
size="normal"
id="recaptcha-google"
onChange={() => setButtonDisabled(false)} // disable the disabled button!
className="mb-3"
/>
<div>
<Button className="mr-3" type="reset" value="Eraser">
Clear
</Button>
<Button type="submit" disabled={buttonDisabled}>
Send
</Button>
</div>
</FormControls>
</Col>
</Row>
</Form>
)
}
const FormControls = styled.div`
display: flex;
align-items: center;
flex-direction: column;
#media ${breakpoints.sm} {
flex-direction: row;
justify-content: space-between;
}
button[disabled] {
cursor: not-allowed;
}
gatsby-config:
require("dotenv").config({
path: `.env.${process.env.NODE_ENV}`,
})
module.exports = {
siteMetadata: {
title: `...`,
description: `...`,
author: `...`,
},
flags: {
DEV_SSR: false,
},
plugins: [
`gatsby-plugin-gatsby-cloud`,
`gatsby-plugin-image`,
`gatsby-plugin-sharp`,
`gatsby-plugin-styled-components`,
`gatsby-plugin-typography`,
`gatsby-plugin-react-helmet`,
`gatsby-transformer-sharp`,
},
}
HTML File in Static Folder:
<form
data-netlify="true"
name="contactVivaz"
method="POST"
data-netlify-honeypot="bot-field"
data-netlify-recaptcha="true"
>
<input type="text" name="first-name" />
<input type="text" name="last-name" />
<input type="email" name="email" />
<input type="tel" name="phone" />
<textarea name="message"></textarea>
<div data-netlify-recaptcha="true"></div>
</form>

Your state management looks good, what it's mandatory is to have (and to check) the input value of hidden fields that must match exactly the form name in the JSX as well as in the Netlify's dashboard. Assuming that everything is well named, as it seems, I believe your issue comes from the Form component, which should looks like:
<Form
name="contact"
method="POST"
action="/thank-you"
data-netlify-honeypot="bot-field"
data-netlify-recaptcha="true"
data-netlify="true"
onSubmit={handleSubmit}
>
Note the data-netlify-honeypot and data-netlify value.
For adding the reCAPTCHA field, you have two options:
Allowing Netlify to handle all the related logic by adding simply an empty <div> like:
<div data-netlify-recaptcha="true"/>
Adding a custom reCAPTCHA (your case) what required to add the environment variables in your Netlify dashboard (prefixed with GATSBY_) and sending the response with the g-recaptcha-response field so your POST request needs to have that field as the docs suggest:
The Netlify servers will check the submissions from that form, and
accept them only if they include a valid g-recaptcha-response value.
Further references to base your setup:
https://www.gatsbyjs.com/docs/building-a-contact-form/
https://www.seancdavis.com/blog/how-to-use-netlify-forms-with-gatsby/
https://medium.com/#szpytfire/setting-up-netlify-forms-with-gatsby-and-react-5ee4f56a79dc

Related

Nodemailer sending attachment using sendinblue

I'm using React-Bootstrap but it is not allowing me to send attachments. It was working before on Sendinblue.
Complaint.JS
import React, { useState } from "react";
import {
Col,
Container,
FloatingLabel,
Form,
Row,
Button,
} from "react-bootstrap";
export default function Complaint() {
const [validated, setValidated] = useState(false);
const [status, setStatus] = useState("Submit");
const handleSubmit = async (e) => {
const form = e.currentTarget;
if (form.checkValidity() === false) {
e.preventDefault();
e.stopPropagation();
}
setValidated(true);
setStatus("Sending...");
const {
complainantName,
violatorName,
complainantAddress,
violatorAddress,
phoneNumber,
emailAddress,
violation,
filesUpload,
} = e.target.elements;
let details = {
cName: complainantName.value,
cAddress: complainantAddress.value,
phone: phoneNumber.value,
email: emailAddress.value,
vName: violatorName.value,
vAddress: violatorAddress.value,
violation: violation.value,
attachments: filesUpload.value,
};
let response = await fetch("http://localhost:5000/complaint", {
method: "POST",
headers: {
"Content-Type": "application/json; charset=utf-8",
},
body: JSON.stringify(details),
});
setStatus("Submit");
let result = await response.json();
alert(result.status);
if (response) setStatus(response.statusText);
};
return (
<Container className="pt-4">
<h4>Complaint Form</h4>
<hr />
<p>
This is the Shadow Lakes Homeowners' Association Board of Directors'
official process for addressing complaints. All complaints will be
confidential and timely handled. The description of the violation must
include the nature of and date of the alleged violation with an
explanation of the factual basis of the complaint. (Who, What, Where,
When, etc.).{" "}
<strong>
Every input boxes must be filled and validated, or the complaint form
will be automatically rejected.
</strong>
</p>
<Form noValidate validated={validated} onSubmit={handleSubmit}>
<Form.Group>
<Row>
<Col>
<FloatingLabel
className="mb-3"
controlId="complainantName"
label="Complainant's Name"
>
<Form.Control
type="text"
placeholder="Complainant's Name"
required
/>
</FloatingLabel>
</Col>
<Col>
<FloatingLabel
className="mb-3"
controlId="violatorName"
label="Violator's Name"
>
<Form.Control
type="text"
placeholder="Violator's Name"
required
/>
</FloatingLabel>
</Col>
</Row>
<Row>
<Col>
<FloatingLabel
className="mb-3"
controlId="complainantAddress"
label="Complainant's Address"
>
<Form.Control
type="text"
placeholder="Complainant's Address"
required
/>
</FloatingLabel>
</Col>
<Col>
<FloatingLabel
className="mb-3"
controlId="violatorAddress"
label="Violator's Address"
>
<Form.Control
type="text"
placeholder="Violator's Address"
required
/>
</FloatingLabel>
</Col>
</Row>
<Row>
<Col>
<FloatingLabel
className="mb-3"
controlId="phoneNumber"
label="Phone Number"
>
<Form.Control type="text" placeholder="Phone Number" required />
<Form.Text className="text-muted">
Phone Number is not to be share with anyone.
</Form.Text>
</FloatingLabel>
</Col>
<Col>
<FloatingLabel
className="mb-3"
controlId="emailAddress"
label="Email Address"
>
<Form.Control
type="text"
placeholder="Email Address"
required
/>
<Form.Text className="text-muted">
Email address is not to be share with anyone.
</Form.Text>
</FloatingLabel>
</Col>
</Row>
<Row>
<Col>
<FloatingLabel
controlId="violation"
label="Description of alleged violation"
className="mb-3"
>
<Form.Control
as="textarea"
placeholder="Description of alleged violation"
style={{ height: "200px" }}
required
/>
<Form.Text className="text-muted">
Description of the alleged violation must be related to Deed
Restrictions. Please review the{" "}
<a href="/deed-restrictions" className="text-black-50">
Deed Restrictions
</a>{" "}
if unsure of the violation.
</Form.Text>
</FloatingLabel>
</Col>
<Row>
<Col>
<Form.Label>Multiple Photos Allowed</Form.Label>
<Form.Control
controlId="filesUpload"
className="mb-3"
type="file"
multiple
/>
</Col>
</Row>
</Row>
</Form.Group>
<Button type="submit" value={"submit"}>
{status}
</Button>
</Form>
</Container>
);
}
Server.js
router.post("/complaint", (req, res) => {
const cName = req.body.cName;
const cAddress = req.body.cAddress;
const phone = req.body.phone;
const email = req.body.email;
const vName = req.body.vName;
const vAddress = req.body.vAddress;
const violation = req.body.violation;
const mail = {
from: "hello#example.com",
to: "hello#example.com",
subject: `Complaint from ${cName} on ${vName}`,
html: `The message is from ${cName} <br />
Complaint's Name: ${cName} <br />
Complaint's address: ${cAddress} <br />
Email: ${email} <br />
Phone: ${phone} <br />
Violator's Name: ${vName} <br />
Violator's Address: ${vAddress} <br />
Violation: ${violation} <br />
Attachment Image(s):<img src="cid:imageFiles" />`,
attachments: [
{
filename: "image.png",
path: "/files/images/",
cid: "imageFiles",
},
],
};
contactEmail.sendMail(mail, (error) => {
if (error) {
res.json({ status: "ERROR" });
} else {
res.json({ status: "Message has been sent" });
}
});
});
There are no error messages when the form is sent. I have changed it directly from the cPanel SMTP and still have the issues. If I remove the codes, then the form will work.
{
filename: "image.png",
path: "/files/images/",
cid: "imageFiles",
},
],
I have had it with
<Form.Group controlId="filesUpload" className="mb-3">
<Form.Label>Multiple Photos Allowed</Form.Label>
<Form.Control type="file" multiple />
</ Form.Group>
I think I am overlooking something. Your help would be greatly appreciated.
attachments: [
{
filename: 'somefile.txt',
contentType: 'text/plain',
content: 'string attachment example'
},
],
Nodemailer Attachment Empty but filename is attached

Next.js form validation with Formik, Yup and React Bootstrap

I'm trying to validate the React Bootstrap form using Formik and Yup. Everything is fine form is validating properly but when I refresh the page from the browser then the below error shows:
This is my contact.js codes:
import React from "react";
import { Button, Card, Col, Container, Form, Row } from "react-bootstrap";
import Head from "next/head";
import { useFormik } from "formik";
import * as Yup from "yup";
export default function Contact() {
const formik = useFormik({
initialValues: {
name: "",
email: "",
subject: "",
message: "",
},
validationSchema: Yup.object({
name: Yup.string()
.required("Required")
.min(3, "Must be at least 3 characters"),
email: Yup.string().email("Invalid email address").required("Required"),
subject: Yup.string().required("Required"),
message: Yup.string().required("Required"),
}),
onSubmit: (values) => {
console.log(JSON.stringify(values, null, 2));
formik.resetForm();
},
});
return (
<>
<Head>
<title>Contact Page</title>
</Head>
<Container>
<Row className="d-flex justify-content-center align-items-center min-vh-100">
<Col md={6}>
<Card className="shadow">
<Card.Header>
<h1 className="fw-bold">Contact</h1>
</Card.Header>
<Card.Body className="p-5">
<Form onSubmit={formik.handleSubmit}>
<Form.Group className="mb-3" controlId="name">
<Form.Label>Name</Form.Label>
<Form.Control
type="text"
name="name"
value={formik.values.name}
onChange={formik.handleChange}
className={
formik.touched.name && formik.errors.name
? "is-invalid"
: ""
}
/>
<Form.Control.Feedback type="invalid">
{formik.errors.name}
</Form.Control.Feedback>
</Form.Group>
<Form.Group className="mb-3" controlId="email">
<Form.Label>Email address</Form.Label>
<Form.Control
type="email"
name="email"
value={formik.values.email}
onChange={formik.handleChange}
className={
formik.touched.email && formik.errors.email
? "is-invalid"
: ""
}
/>
<Form.Control.Feedback type="invalid">
{formik.errors.email}
</Form.Control.Feedback>
</Form.Group>
<Form.Group className="mb-3" controlId="subject">
<Form.Label>Subject</Form.Label>
<Form.Control
type="text"
name="subject"
value={formik.values.subject}
onChange={formik.handleChange}
className={
formik.touched.subject && formik.errors.subject
? "is-invalid"
: ""
}
/>
<Form.Control.Feedback type="invalid">
{formik.errors.subject}
</Form.Control.Feedback>
</Form.Group>
<Form.Group className="mb-3" controlId="message">
<Form.Label>Message</Form.Label>
<Form.Control
as="textarea"
name="message"
rows={3}
value={formik.values.message}
onChange={formik.handleChange}
className={
formik.touched.message && formik.errors.message
? "is-invalid"
: ""
}
/>
<Form.Control.Feedback type="invalid">
{formik.errors.message}
</Form.Control.Feedback>
</Form.Group>
<Form.Group controlId="submitButton">
<Button variant="primary" type="submit">
Send
</Button>
</Form.Group>
</Form>
</Card.Body>
</Card>
</Col>
</Row>
</Container>
</>
);
}
and this is my _document.js page codes:
import Document, { Html, Head, Main, NextScript } from "next/document";
class MyDocument extends Document {
static async getInitialProps(ctx) {
const originalRenderPage = ctx.renderPage;
// Run the React rendering logic synchronously
ctx.renderPage = () =>
originalRenderPage({
// Useful for wrapping the whole react tree
enhanceApp: (App) => App,
// Useful for wrapping in a per-page basis
enhanceComponent: (Component) => Component,
});
// Run the parent `getInitialProps`, it now includes the custom `renderPage`
const initialProps = await Document.getInitialProps(ctx);
return initialProps;
}
render() {
return (
<Html>
<Head>
<link
href="https://fonts.googleapis.com/css2?family=Poppins:wght#200;300;400;500;600;700;800;900&display=swap"
rel="stylesheet"
type="text/css"
/>
</Head>
<body style={{ fontFamily: "Poppins, sans-serif" }}>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default MyDocument;
I've tried to delete the _document.js file as well but still the same error showing.
Please help me to fix this error.

How to pass a data one Component to Another Components After Form Submit

In this code, I want to get my user email in Login Component after submitting the Registration Component.
Component: Registration
import React, { useState } from 'react';
import { Button, Container, Form,Row,Col } from 'react-bootstrap';
import { useNavigate,Navigate } from 'react-router-dom';
const Register = () => {
const [data,setData] = useState({
'first_name': 'dfdf',
'last_name': '',
'email': 'maruf#mail.com',
'password': '',
'password_confirm': ''
})
let navigate = useNavigate();
const handleInputChange = (e) => {
setData({
...data,
[e.target.name]: e.target.value,
});
};
const handleSubmit = (e) => {
e.preventDefault();
console.log(data);
navigate('/login',{replace:true,state:{email:data.email}});
}
return <>
<Container fluid={'md'}>
<Row>
<Col xs={6}>
<Form onSubmit={handleSubmit}>
<Form.Group className="mb-3" controlId="formBasicFirstName">
<Form.Label column >First Name</Form.Label>
<Form.Control name='first_name' value={data.first_name} onChange={handleInputChange} type="text" placeholder="First Name" />
</Form.Group>
<Form.Group className="mb-3" controlId="formBasicLastName">
<Form.Label>Last Name</Form.Label>
<Form.Control name='last_name' value={data.last_name} onChange={handleInputChange} type="text" placeholder="Last Name" />
</Form.Group>
<Form.Group className="mb-3" controlId="formBasicEmail">
<Form.Label>Email address</Form.Label>
<Form.Control name='email' value={data.email} onChange={handleInputChange} type="email" placeholder="Enter email" />
</Form.Group>
<Form.Group className="mb-3" controlId="formBasicPassword">
<Form.Label>Password</Form.Label>
<Form.Control name='password' value={data.password} onChange={handleInputChange} type="password" placeholder="Password" />
</Form.Group>
<Form.Group className="mb-3" controlId="formBasicPassword_Confirm">
<Form.Label>Password</Form.Label>
<Form.Control name='password_confirm' value={data.password_confirm} onChange={handleInputChange} type="password" placeholder="Confirm Password" />
</Form.Group>
<Button variant="primary" type='submit' onSubmit={handleSubmit} >Register</Button>
</Form>
</Col>
</Row>
</Container>
</>;
};
export default Register;
here I want to send the user email address after done the registration then send the data into the Login Components.
Component: Login
React, { useEffect, useState } from "react";
import { Button, Col, Container, Form, Row } from "react-bootstrap";
import { useLocation } from "react-router-dom";
import { Navigate, useNavigate } from "react-router-dom";
const Login = () => {
const [data,setData] = useState({
email: "",
password: "",
});
const uselocation = useLocation();
if (uselocation.state) {
if (uselocation.state.email) {
setData({
...data,
email: uselocation.state.email,
});
}
}
const handleSubmit = (e) => {
e.preventDefault();
console.log(data);
};
return (
<>
<Container fluid={'md'}>
<Row>
<Col xs={6}>
<Form onSubmit={handleSubmit}>
<Form.Group className="mb-3" controlId="formBasicEmail">
<Form.Label>Email address</Form.Label>
<Form.Control type="email" placeholder="Enter email" />
<Form.Text className="text-muted">
We'll never share your email with anyone else.
</Form.Text>
</Form.Group>
<Form.Group className="mb-3" controlId="formBasicPassword">
<Form.Label>Password</Form.Label>
<Form.Control type="password" placeholder="Password" />
</Form.Group>
<Form.Group className="mb-3" controlId="formBasicCheckbox">
<Form.Check type="checkbox" label="Check me out" />
</Form.Group>
<Button variant="primary" type="submit">
Submit
</Button>
</Form>
</Col>
</Row>
</Container>
</>
);
};
export default Login;
after a navigate to login Component I got this error
Uncaught Error: Too many re-renders. React limits the number of
renders to prevent an infinite loop.
Wrap setData from Login component with useEffect and add location as a dependency.

Two Antd forms, one component

I have two antd forms within a single component. The first form is a register form where a user inputs various information (firstname, lastname, email, etc..) The submit button triggers a function to open a modal with another form for them to verify their phone number by generating a code that is texted to them. Once the code is typed and they hit verify, it verifies if it is the correct code - then i would like for it to register the user but I am having difficulties pulling in the values from the first form..
Is there a specific way to go about doing this? I thought maybe I could utilize useState and set the values to component level state but even that didnt work..
form
<Form
layout="vertical"
name="register-form"
initialValues={initialValues}
onFinish={handleVerification}
>
<Row gutter={ROW_GUTTER}>
<Col xs={24} sm={24} md={12}>
<Form.Item
name="firstName"
label="First Name"
rules={rules.firstName}
hasFeedback
>
<Input placeholder="Enter First Name" />
</Form.Item>
</Col>
<Col xs={24} sm={24} md={12}>
<Form.Item
name="lastName"
label="Last Name"
rules={rules.lastName}
hasFeedback
>
<Input placeholder="Enter Last Name" />
</Form.Item>
</Col>
</Row>
<Row gutter={ROW_GUTTER}>
<Col xs={24} sm={24} md={12}>
<Form.Item
name="phone"
label="Phone Number"
rules={rules.phone}
hasFeedback
>
<Input placeholder="Enter Phone Number" />
</Form.Item>
</Col>
<Col xs={24} sm={24} md={12}>
<Form.Item name="city" label="City" rules={rules.city} hasFeedback>
<Select placeholder="Select City">
<Option value="Lancaster, PA">Lancaster, PA</Option>
</Select>
</Form.Item>
</Col>
</Row>
<Form.Item
name="email"
label="Email Address"
rules={rules.email}
hasFeedback
>
<Input placeholder="Enter Email Address" />
</Form.Item>
<Form.Item
name="password"
label="Password"
rules={rules.password}
hasFeedback
>
<Input.Password placeholder="Enter Password" />
</Form.Item>
<Form.Item
name="confirmPassword"
label="Confirm Password"
rules={rules.confirm}
hasFeedback
>
<Input.Password placeholder="Confirm Password" />
</Form.Item>
<Form.Item name="tos" valuePropName="checked">
<Checkbox>
I agree to the <Link to="/">Terms of Service</Link> and{' '}
<Link to="/">Privacy Policy</Link>.
</Checkbox>
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit" block>
Register
</Button>
</Form.Item>
</Form>
<Modal
title="Account Verification"
centered
visible={modal}
onOk={() => setModal(false)}
onCancel={() => setModal(false)}
>
<p>
To finish registering, please enter the verification code we just sent
to your phone. If you didn't receive a code, make sure your entered
phone number is correct and sign up again. Your code will expire upon
closing this popup.
</p>
<Form layout="vertical" name="verify-phone-form" onFinish={onSubmit}>
<Form.Item name="enteredCode" label="Verify">
<Input placeholder="Enter Code" />
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit" block>
Verify
</Button>
</Form.Item>
</Form>
</Modal>
handleVerification
const handleVerification = async (values) => {
const { phone, email } = values;
setModal(true);
try {
const response = await postRegisterCheckDuplicate({ email, phone });
if (response.data.success) {
switch (response.data.message) {
case 0:
try {
const response = await dispatch(
attemptRegisterVerify({ to: phone })
);
console.log('handleVerification: ', response.message);
if (response.success) {
setGeneratedCode(response.message);
} else {
console.log(response.message);
}
} catch (error) {
console.log(error);
}
break;
case 1:
console.log('Email Address already in use.');
break;
case 2:
console.log('Phone number already in use.');
break;
case 3:
console.log('Email and Phone in use.');
break;
}
} else {
console.log(response.data.message);
}
} catch (error) {
console.log(error);
}
};
onSubmit
const onSubmit = (values) => {
const { enteredCode } = values;
if (generatedCode === enteredCode) {
try {
console.log('values :', values);
// dispatch(attemptRegister(values));
} catch (error) {
console.log(error);
}
} else {
console.log('Verification code incorrect');
}
};
You can create a form instance (hooks) and reference it to the first form so you can use the api of the instance. You can check more here antd FormInstance
const [registerForm] = Form.useForm();
const handleSubmit = (values) => {
const { enteredCode } = values;
console.log(registerForm.getFieldsValue());
//output is the values in the first form
};
<Form form={registerForm} layout="vertical" onFinish={handleVerification}>
...
</Form>
I created a small version of your work. See working code here:
You can also check this one antd control between forms

Npm reactjs -input -validators

index.js:1446 Warning: React does not recognize the validatorErrMsg prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase validatorerrmsg instead. If you accidentally passed it from a parent component, remove it from the DOM element.
in input (created by t)
in div (created by t)
in t (created by t)
in div (created by t)
in t (created by t)
in div (created by t).
This is the Error which stuck my brain since two days..
The required js file include following code .
class SharedComponent extends Component {
constructor() {
super();
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.state = {
data: {},
};
}
handleChange(event, inputValue, inputName, validationState, isRequired) {
const value = (event && event.target.value) || inputValue;
const { data } = this.state;
data[inputName] = { value, validation: validationState, isRequired };
this.setState({
data,
});
const formData = formInputData(this.state.data);
const isFormValid = formValidation(this.state.data);
console.log('shared component',formData+isFormValid);
}
handleSubmit(event) {
event.preventDefault();
const isFormValid = formValidation(this.state.data);
if (isFormValid) {
// do anything including ajax calls
this.setState({ callAPI: true });
} else {
this.setState({ callAPI: true, shouldValidateInputs: !isFormValid });
}
}
render() {
const passwordValue = this.state.data.password && this.state.data.password.value;
return (
<form className="example">
<Row>
<Col md={6}>
<Field required
label="Full Name" name="fullName" placeholder="First Last"
onChange={this.handleChange}
value={this.state.data.fullName}
shouldValidateInputs={this.state.shouldValidateInputs}
/>
</Col>
<Col md={6}>
<Field
validator="isEmail" required
label="Email" name="email" placeholder="Email"
onChange={this.handleChange}
value={this.state.data.email}
shouldValidateInputs={this.state.shouldValidateInputs}
/>
</Col>
</Row>
<Row>
<Col md={6}>
<Field
validator="isAlphanumeric" required minLength={8}
minLengthErrMsg="Short passwords are easy to guess. Try one with atleast 8 characters"
label="Create a password" name="password" type="password" placeholder="Password"
onChange={this.handleChange}
value={this.state.data.password}
shouldValidateInputs={this.state.shouldValidateInputs}
/>
</Col>
<Col md={6}>
<Field
validator="equals" required comparison={passwordValue}
validatorErrMsg="These passwords don't match. Try again?"
label="Confirm password" name="confirmPassword" type="password" placeholder="Password"
onChange={this.handleChange}
value={this.state.data.confirmPassword}
shouldValidateInputs={this.state.shouldValidateInputs}
/>
</Col>
</Row>
<Field
required
requiredErrMsg="Enter your address so we can send you awesome stuff"
label="Address" name="address" placeholder="1234 Main St"
onChange={this.handleChange}
value={this.state.data.address}
shouldValidateInputs={this.state.shouldValidateInputs}
/>
<Field
label="Address 2"
name="address2" placeholder="Apartment, studio, or floor"
onChange={this.handleChange}
value={this.state.data.address2}
shouldValidateInputs={this.state.shouldValidateInputs}
/>
<Row>
<Col md={6}>
<Field
maxLength={20} required label="City"
name="inputCity"
onChange={this.handleChange}
value={this.state.data.inputCity}
shouldValidateInputs={this.state.shouldValidateInputs}
/>
</Col>
<Col md={3}>
<label htmlFor="inputState">State</label>
<select
name="inputState" className="form-control"
onChange={this.handleChange}
value={this.state.data.inputState ? this.state.data.inputState.value : ''}
>
<option>Choose...</option>
<option value="ALABAMA">ALABAMA</option>
<option value="ALASKA">ALASKA</option>
<option value="ARIZONA">ARIZONA</option>
<option>...</option>
</select>
</Col>
<Col md={3}>
<Field
validator="isPostalCode" locale="US" required maxLength={10}
validatorErrMsg="Enter a valid US Zip"
label="Zip" name="inputZip"
onChange={this.handleChange}
value={this.state.data.inputZip}
shouldValidateInputs={this.state.shouldValidateInputs}
/>
</Col>
</Row>
<button
type="submit" onClick={this.handleSubmit} className="btn btn-danger"
>Sign up
</button>
{this.state.callAPI
?
<pre className="resultBlock">
{JSON.stringify(formInputData(this.state.data), null, 4)}
</pre>
: null
}
</form>
);
}
}
This is my js file for rect js form with validation .
Can Anyone help to walk through it ..THANKS.
The message you're seeing means that the Field component isn't itself doing anything with the validatorErrMsg prop; instead, it's simply passing it down to the DOM node (probably an input element). That property has no special meaning to input elements, so it has no effect.
You need to check the documentation for whatever library you're getting Field from. That should specify what props you can use.
Alternatively, if you created the Field component yourself, you need to implement the logic for handling the validatorErrMsg prop yourself, within that component.

Resources