Good morning @jen, and thanks for your reply.
I wrote also a question here but we can continue on this thread
I’ve tried your way but it doesn’t work as well. To give to you a little bit of contect, I’m using Formik to render my form, so at the moment the only thing not implement is the e.preventDefault()
method at the end of the post function. Here’s the form itself:
<Formik
enableReinitialize
validationSchema={ContactSchema}
initialValues={{
name: '',
email: '',
message: '',
}}
onSubmit={(values, { setSubmitting }) => {
handleSubmit(values);
setSubmitting(false);
}}
>
{({
touched,
errors,
values,
handleChange,
handleBlur,
handleSubmit,
}) => (
<Form
name="contact-us"
data-netlify="true"
data-netlify-honeypot="bot-field"
onSubmit={handleSubmit}
{...bem('form')}
>
<FieldSet {...bem('fieldset')}>
<InputField
type="text"
name="name"
inputId="name"
labelText={nameInputLabel}
value={values.name}
error={touched.name && errors.name}
touched={touched.name}
onChange={handleChange}
onBlur={handleBlur}
isRequired
{...bem('contact-name')}
/>
<InputField
type="email"
name="email"
inputId="email"
labelText={emailInputLabel}
value={values.email}
error={touched.email && errors.email}
touched={touched.email}
onChange={handleChange}
onBlur={handleBlur}
isRequired
{...bem('email')}
/>
<InputField
type="textarea"
name="message"
label=""
inputId="message"
placeholder={textFieldPlaceholder}
value={values.message}
error={touched.message && errors.message}
touched={touched.message}
onChange={handleChange}
onBlur={handleBlur}
isRequired
{...bem('message')}
/>
<Button
variant="primary"
type="submit"
{...bem('button')}
>
{submitButtonLabel}
</Button>
</FieldSet>
</Form>
)}
</Formik>
The point is that, since I’m manually set the values on the post request, why the form gets other values form the form labels? Here are the console.log
of the data I’m supposed to send,
-
with the
encode
method:form-name=contact-us&name=Ivan&email=ivan.test%40test.com&message=Test%20message
-
with the
createFormDataObj
method:form-name=contact-us&name=Ivan&email=ivan%40test.com&message=Test+message+for+you
As you can see in both the cases the labels are set correctly set, but apparently not sent, and in the end is not what I get on the dashboard