Skip to content
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

Parsing checkbox value "on" as a bool #50

Open
alexflint opened this issue Jul 26, 2024 · 1 comment
Open

Parsing checkbox value "on" as a bool #50

alexflint opened this issue Jul 26, 2024 · 1 comment

Comments

@alexflint
Copy link

alexflint commented Jul 26, 2024

If I write an html form with a checkbox that has no explicit value attribute then when the checkbox is checked by the user the browser will send the string "on" in the form data. However, the string "on" is not recognized by strconv.ParseBool and I get a parse error. It would be nice if this library handled this case.

I realize that I can work around this by setting value="true" in my HTML form but I was wondering whether you would consider making that unnecessary by processing the string "on" as true when parsing booleans.

@arp242
Copy link
Collaborator

arp242 commented Jul 26, 2024

I'd have to check to be sure, but I'm pretty sure this should be handled: https://github.com/monoculum/formam/blob/master/formam.go#L501 – it doesn't call strconv.ParseBool() at all.

What does your HTML and code look like? Are you sure there isn't some error there? Also what error do you get?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants