Next.js Discord

Discord Forum

How do i read post request body?

Unanswered
Masai Lion posted this in #help-forum
Open in Discord
Masai LionOP
How do I read the data sent through a form tag via the body with the POST method?

app/page.tsx
    <form className="h-screen flex items-center justify-center text-white" method="post" action={"/dash"}>
      <input className="text-black" name="pass" />
      <button type="submit">login</button>
    </form>


app/dash/page.tsx
export default async function (R: any) {
    console.log(R)
    return <></>
}

5 Replies

make a server action and then you can access the formdata in that function - this will still work as progressive enhancement with no js

or... you can make route handler but then you cant have page as a result of it
@B33fb0n3 the page itself can't get this data. However an api route can. So you an api route (route handler) instead
Masai LionOP
but..i need to send an page if the given data is correct, then i guess will use get method and access with query
@Masai Lion but..i need to send an page if the given data is correct, then i guess will use get method and access with query
you should use server action with useFormState (or useActionState if using nextjs rc)
do what risky is saying. He's good and right