How to submit 0 if checkbox is unchecked and submit 1 if checkbox is checked in HTML

后端 未结 3 1533
闹比i
闹比i 2020-12-09 08:40

How to submit value 1 if a checkbox in a checkbox array is checked, and submit 0 if it\'s unchecked? I tried this but no luck. I am trying to grab this array in a php array

3条回答
  •  粉色の甜心
    2020-12-09 09:05

    A better solution that solved this for me.

    Problem: Both the hidden and the checked were sending to my server.

    Solution:

    if len(key) == 1 {
      value = false
    } else {
      value = true
    }
    

    This way, if len(key) is 1 I know that only the hidden field was being send. Any other scenario means that the box is checked. Simple and easy.

提交回复
热议问题