-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🤗 [Question]: How do we get multiple values for a key in form submission? #3159
Comments
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 |
For JSON it will work JSON test
For forms it will not work if you allow comma (,) in value. Form test
|
It seems like EnableSplittingOnParsers has lost its functionality during the migration of the codebase from v2 to v3. We have to add v2: if c.app.config.EnableSplittingOnParsers && strings.Contains(v, ",") && equalFieldType(out, reflect.Slice, k, bodyTag) {
values := strings.Split(v, ",")
for i := 0; i < len(values); i++ {
data[k] = append(data[k], values[i])
}
} else {
data[k] = append(data[k], v)
} v3: if strings.Contains(v, ",") && equalFieldType(out, reflect.Slice, k) {
values := strings.Split(v, ",")
for i := 0; i < len(values); i++ {
data[k] = append(data[k], values[i])
}
} else {
data[k] = append(data[k], v)
} Will work on the fix. Thanks for the bug report. |
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: