You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a field in my form, its name is the description
Example:
<input name="item" value="item1">
<input name="description" value="description1, this is a description for item one, the first item is very nice, bla bla bla">
<input name="item" value="item2">
<input name="description" value="description2">
<input name="item" value="item3">
<input name="description" value="description3">
On my server side, I define a struct with the information:
I have a problem with binding data from the form to my formData.
My expectation data for formData.Description is []string{"description, this is a description for item one, the first item is very nice, bla bla bla", "description2", "description3"} (This has 3 values for the slice).
But currently, I received for formData.Description after binding data is []string{"description1", "this is a description for item one", "the first item is very nice", "bla bla bla", "description2", "description3"} (This has 6 values for the slice).
It seems that the Bind() function has split the value of the description field of the first item into a slice by the "," , so I received the data for formData.Description is []string{"description1", "this is a description for item one", "the first item is very nice", "bla bla bla", "description2", "description3"}.
Who can resolve my problem?
Thank you so much!
Code Snippet (optional)
package main
import"github.com/gofiber/fiber/v3"import"log"funcmain() {
app:=fiber.New()
// An example to describe the questionapp.Post("/create-post", handleCreate)
log.Fatal(app.Listen(":3000"))
}
functionhandleCreate(cfiber.Ctx) error{
FormCreatestruct {
Item []string`json:"item" form:"item"`Description []string`json:"description" form:"description"`
}
var (
formData=new(FormCreate)
)
ifc.Method() == http.MethodPost {
err=c.Bind().Body(formData)
}
returnc.Render("index", fiber.Map{
"formData": formData,
})
}
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord
Question Description
I have a field in my form, its name is the description
Example:
On my server side, I define a struct with the information:
I have a problem with binding data from the form to my formData.
My expectation data for formData.Description is []string{"description, this is a description for item one, the first item is very nice, bla bla bla", "description2", "description3"} (This has 3 values for the slice).
But currently, I received for formData.Description after binding data is []string{"description1", "this is a description for item one", "the first item is very nice", "bla bla bla", "description2", "description3"} (This has 6 values for the slice).
It seems that the Bind() function has split the value of the description field of the first item into a slice by the "," , so I received the data for formData.Description is []string{"description1", "this is a description for item one", "the first item is very nice", "bla bla bla", "description2", "description3"}.
Who can resolve my problem?
Thank you so much!
Code Snippet (optional)
Checklist:
The text was updated successfully, but these errors were encountered: