Troubles when submitting forms
Unanswered
Asiatic Lion posted this in #help-forum
Asiatic LionOP
When I submit a form - my form values get added to the URL of the page and my onSubmitHandle function doesn't even get called.
I've tried adding method='post' to my <form> element but then the page reloads and nothing happens, still no api call.
I've tried adding method='post' to my <form> element but then the page reloads and nothing happens, still no api call.
8 Replies
Asiatic LionOP
@joulev
const ContactForm = ({ className }: Props) => {
const t = useTranslations();
const handleContactSubmit = async (values: ContactFormValue) => {
try {
await api.contact.contactPerformai(values);
} catch (err) {
utils.toastError(err);
}
};
return (
<section className={classNames("home__form", className)}>
<h2>{t("Form.header")}</h2>
<h3 className="home__form__explanation">{t("Form.paragraph")}</h3>
<Form
onSubmit={handleContactSubmit}
render={() => (
<form method="post">
<Field
component={InputField}
id="fullName"
name="fullNAme"
type="text"
label={t("Form.fullName")}
/>
<Field
component={InputField}
id="email"
name="email"
type="email"
label="EMAIL"
/>
<Field
component={InputField}
id="Phone Number"
name="phoneNumber"
type="number"
label={t("Form.phoneNumber")}
/>
<Field
component={InputField}
id="companyName"
name="companyName"
type="text"
label={t("Form.companyName")}
/>
<Button type="submit">{t("Form.button")}</Button>
</form>
)}
/>
</section>
);
};@Asiatic Lion <@484037068239142956>
const ContactForm = ({ className }: Props) => {
const t = useTranslations();
const handleContactSubmit = async (values: ContactFormValue) => {
try {
await api.contact.contactPerformai(values);
} catch (err) {
utils.toastError(err);
}
};
return (
<section className={classNames("home__form", className)}>
<h2>{t("Form.header")}</h2>
<h3 className="home__form__explanation">{t("Form.paragraph")}</h3>
<Form
onSubmit={handleContactSubmit}
render={() => (
<form method="post">
<Field
component={InputField}
id="fullName"
name="fullNAme"
type="text"
label={t("Form.fullName")}
/>
<Field
component={InputField}
id="email"
name="email"
type="email"
label="EMAIL"
/>
<Field
component={InputField}
id="Phone Number"
name="phoneNumber"
type="number"
label={t("Form.phoneNumber")}
/>
<Field
component={InputField}
id="companyName"
name="companyName"
type="text"
label={t("Form.companyName")}
/>
<Button type="submit">{t("Form.button")}</Button>
</form>
)}
/>
</section>
);
};
Where is that Form (not form) from?
I think that Form already renders a form component for you. Change the <form> to a #Unknown Channel
I think that Form already renders a form component for you. Change the <form> to a #Unknown Channel
@joulev Where is that Form (not form) from?
I think that Form already renders a form component for you. Change the <form> to a <>
Asiatic LionOP
it's from react-final-form
The method=post is irrelevant here, remove it
Asiatic LionOP
the problem was that i didnt pass handleSubmit from FinalForm to form onSubmit
<Form
onSubmit={handleContactSubmit}
render={({ handleSubmit }) => (
<form onSubmit={handleSubmit}>it's fixed now, thanks