Description
Hi,
After a lot of googling, I couldn't find anything. There is some content about Checkbox groups but it doesn't meet my need.
How to reproduce
This is the form:
<form action="/p1" method="post">
<label for="ex-checkbox">a checkbox</label>
<input type="checkbox" name="ex-checkbox" />
</form>
Go code:
.......
type CheckboxForm {
// checked or unchecked > true or false
CheckboxStatus bool `form:"ex-checkbox"`
}
var form CheckboxForm
err = c.ShouldBind(&form)
if err != nil {
panic(err)
}
fmt.Println(form)
....
Expectations
if checkbox is cheched field is true, or false
Actual result
Environment
Comment From: thoohv5
input checkbox value is no or "", so not use boolean, use string; judge value
Comment From: Gasoid
<input type="checkbox" name="ex-checkbox" value="yes"/>
type CheckboxForm struct{
CheckboxStatus string `form:"ex-checkbox"`
}
Comment From: SeanTolstoyevski
Thank you so much.
I will try it.
Comment From: abo1000ody
Description
Hi,
After a lot of googling, I couldn't find anything. There is some content about Checkbox groups but it doesn't meet my need.
How to reproduce
This is the form:
<form action="/p1" method="post"> <label for="ex-checkbox">a checkbox</label> <input type="checkbox" name="ex-checkbox" /> </form>
Go code:
``` .......
type CheckboxForm { // checked or unchecked > true or false CheckboxStatus bool
form:"ex-checkbox"
} var form CheckboxForm err = c.ShouldBind(&form) if err != nil { panic(err) } fmt.Println(form) .... ```Expectations
if checkbox is cheched field is true, or false
Actual result
Environment