Codeigniter checking checkbox value

后端 未结 5 880
抹茶落季
抹茶落季 2021-01-13 00:46

I\'m using CodeIgniter and I have a form with a checkbox that allows the user to check and remove their uploaded photo.
In my controller I use if(isset($checked)

5条回答
  •  我在风中等你
    2021-01-13 01:39

    What you need to do here is to change this line ...

    if(isset($checked) == 1){
    

    to

    if((int) $checked == 1){
    

    The reason is that the variable $checked will always be set whether its value is 1 or not. $checked = $this->input->post('remove'); will return NULL if the 'remove' is not set in the POST data.

提交回复
热议问题