How get value for unchecked checkbox in checkbox elements when form posted?

前端 未结 11 2450
独厮守ぢ
独厮守ぢ 2020-11-27 17:13

I have a form like below :

11条回答
  •  天涯浪人
    2020-11-27 17:36

    First way - hidden fields (disadvantage: the user can manipulate the value of the field (but one can manipulate the value of the checkbox too, so it's not really a problem, if you only expect 1 or 0))

    
    
    
    
    
    
    
    
    
     string '0' (length=1)
      'status_2' => string '1' (length=1)
      'status_3' => string '0' (length=1)
     */
    

    Second way - to assign default value for non-set indexes:

    string '1' (length=1) 'status_1' => int 0 'status_2' => int 0 */

提交回复
热议问题