Next.js Discord

Discord Forum

How to pass form data to server action

Answered
Rhinelander posted this in #help-forum
Open in Discord
Avatar
RhinelanderOP
      <form action={checkout}>
            <Button className="w-full" disabled={pending}>
              {pending ? "Pojdi na blagajno" : "Preusmerjam..."}
            </Button>
          </form>


How do I pass form data to server action. My form data is "product" - object that i get from my context.

I know how to pass each individual value but doesn't seem right (invisible input...).

How do I pass entire object to form data.
Answered by Julienng
Hi! Do you really need to pass the full object?

Is passing the ID enough? Like: <input type="hidden" name="id" value={myObjectId} />
View full answer

4 Replies

Avatar
Hi! Do you really need to pass the full object?

Is passing the ID enough? Like: <input type="hidden" name="id" value={myObjectId} />
Answer
Avatar
RhinelanderOP
Yeah you are right. Than i also need to send size and quantity but apart from that id will be enough. Thank you
Avatar
RhinelanderOP
Thank you