Server actions not returning the data
Unanswered
Cuvier’s Dwarf Caiman posted this in #help-forum
Cuvier’s Dwarf CaimanOP
I am trying to make a form using nextjs server actions. It looks something like:
The formData doesn't contain the data entered in inputs.
Also btw, the
<form action={handleSubmit}>
<div className="w-screen h-screen flex justify-center items-center bg-cover">
<div className="grid justify-center items-center p-16 rounded bg-[rgba(0,0,0,0.80)]">
<Input label="Email" type="text" placeholder="Enter your email" />
<Input label="Password" type="password" placeholder="Enter your password" />
<Button type="submit">Login</Button>
</div>
</div>
</form>
); and the action like async function handleSubmit(formData: FormData) {
'use server';
console.log(formData);
} defined within the same function as component.The formData doesn't contain the data entered in inputs.
Also btw, the
<Input /> component just a custom input nested inside a div if that matters.12 Replies
@gin try with typescript
formData.get()
Cuvier’s Dwarf CaimanOP
Still the same. The object only contains an ACTION_ID string nothing else
@Cuvier’s Dwarf Caiman Still the same. The object only contains an ACTION_ID string nothing else
is your handleSubmit inside the same component as the form
without "use client" or "use server" at the top
@@ts-ignore try to add `name` prop to inputs and then try
ah yeah i just see
@gin is your handleSubmit inside the same component as the form
Cuvier’s Dwarf CaimanOP
It is but with use server at the top of the action function
do what yi lon ma said
@@ts-ignore try to add `name` prop to inputs and then try
Cuvier’s Dwarf CaimanOP
Ohh yeah this works
Thank you. Totally forget about adding a name lol
You're most welcome