79477379

Date: 2025-03-01 09:56:02
Score: 0.5
Natty:
Report link

Can't find a direct solution, but have solved already. Just added a hidden field with Ids and iterate over them on POST request. Here is the form:

<form action="/providers" method="post">
    <input type="hidden" value="1,8,9,10" name="providerids">

    <input type="checkbox" id="state-1" name="state-1" checked><label for="state">Provider 1</label>
    <input type="checkbox" id="state-8" name="state-8" checked><label for="state">Provider 8</label>
    <input type="checkbox" id="state-9" name="state-9" checked><label for="state">Provider 0</label>
    <input type="checkbox" id="state-11" name="state-10" checked><label for="state">Provider 10</label>
</form>

Here is Go code:

providerIds := c.FormValue("providerids")
Ids := strings.Split(providerIds, `,`)
for _, id := range Ids {
    val[id] = c.FormValue("state-" + id)
}

Not a perfect but works.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Starts with a question (0.5): Can't find a
  • Low reputation (0.5):
Posted by: Petr Lozovitskii