How to read if a checkbox is checked in PHP?

后端 未结 18 952
刺人心
刺人心 2020-11-22 07:54

How to read if a checkbox is checked in PHP?

18条回答
  •  伪装坚强ぢ
    2020-11-22 08:28

    To check if a checkbox is checked use empty()

    When the form is submitted, the checkbox will ALWAYS be set, because ALL POST variables will be sent with the form.

    Check if checkbox is checked with empty as followed:

    //Check if checkbox is checked    
    if(!empty($_POST['checkbox'])){
     #Checkbox selected code
    } else {
     #Checkbox not selected code
    }
    

提交回复
热议问题