onSubmit won't run
Answered
Nile Crocodile posted this in #help-forum
Nile CrocodileOP
hi,
I have this client component:
but the code in the onSubmit doesn't run. nothing in the console, and no visible effects whatsoever. nothing happens. my IDE says
I have this client component:
"use client";
import { FormEvent } from "react";
export default function LogInForm()
{
function onLogInSubmit(event: FormEvent<HTMLFormElement>)
{
console.log("hi");
event.preventDefault();
const formData = new FormData(event.currentTarget);
const email = formData.get("emailField") as string;
const password = formData.get("passwordField") as string;
alert(email + " " + password);
}
return (
<>
<form onSubmit={onLogInSubmit}>
<input type="email" name="emailField" /><br />
<input type="password" name="passwordField" /><br />
<input type="submit" value="Log In" />
</form>
</>
);
}but the code in the onSubmit doesn't run. nothing in the console, and no visible effects whatsoever. nothing happens. my IDE says
FormEvent is deprecated but I can't find what else I could possibly use online, since FormEvent is what the NextJS documentation tells me to use. something very simple has become very confusing. any advice to point me in the right direction would be very much appreciatedAnswered by Nile Crocodile
nvm figured it out, firefox wasn't submitting my form because I wasn't entering a valid email in the email field
3 Replies
Nile CrocodileOP
nvm figured it out, firefox wasn't submitting my form because I wasn't entering a valid email in the email field
Answer
Nile CrocodileOP
my code worked the entire time
I hate frontend web dev