Skip to content

Bind a checkbox group #129

Closed
Closed
@phrozen

Description

Hey I have the following code:

<input type="checkbox" name="colors" value="red">Red&nbsp;
<input type="checkbox" name="colors" value="green">Green&nbsp;
<input type="checkbox" name="colors" value="blue">Blue&nbsp;
<input type="checkbox" name="colors" value="black">Black&nbsp;
<input type="checkbox" name="colors" value="white">White&nbsp;

What is the correct way to bind them (using Bind Middleware) to obtain all data from them? I'm binding to an string but I only get the first one, if I bind to a slice I get an error.

Any ideas? Does Bind support this?

This is done in other languages by naming the group as an array:

<input type="checkbox" name="colors[]" value="purple">Purple&nbsp;

Then my struct will have a slice to bind. But I can't seem to make it work here.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions