Server Actions multiple Form Inputs with same name attribute
Answered
Eastern Phoebe posted this in #help-forum
Eastern PhoebeOP
I’m currently working on an app using Next.js where users can create multiple items dynamically. Each item has the same name attribute, and I noticed that when I use server actions, I only receive one of them instead of an array or a way to capture all the items.
(A screenshot for reference is appended to the post)
I'm wondering how I can handle multiple items with the same name attribute and receive them on the server side, possibly as an array or an alternative solution. Also, I'm planning to implement validation using Zod in the future, so any insights on how to integrate that with multiple items would be appreciated.
(A screenshot for reference is appended to the post)
I'm wondering how I can handle multiple items with the same name attribute and receive them on the server side, possibly as an array or an alternative solution. Also, I'm planning to implement validation using Zod in the future, so any insights on how to integrate that with multiple items would be appreciated.
Answered by Ray
just assign them same name in the form, eg:
item. then on server formData.getAll("item")2 Replies
@Eastern Phoebe I’m currently working on an app using Next.js where users can create multiple items dynamically. Each item has the same name attribute, and I noticed that when I use server actions, I only receive one of them instead of an array or a way to capture all the items.
(A screenshot for reference is appended to the post)
I'm wondering how I can handle multiple items with the same name attribute and receive them on the server side, possibly as an array or an alternative solution. Also, I'm planning to implement validation using Zod in the future, so any insights on how to integrate that with multiple items would be appreciated.
just assign them same name in the form, eg:
item. then on server formData.getAll("item")Answer
@Ray just assign them same name in the form, eg: `item`. then on server `formData.getAll("item")`
Eastern PhoebeOP
its working 🎉 tysm youre the goat