Codeigniter checking checkbox value

后端 未结 5 837
抹茶落季
抹茶落季 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:18

    remove isset

    its because by default in your CI Controller you get input value using

    $checked = $this->input->post('remove');

    whether is has a value or not your variable now exist..

    0 讨论(0)
  • 2021-01-13 01:26

    Please write proper value in your checkbox :-

       <input id="remove" type="checkbox" name="remove">
    

    Write some value then check it :-

    for e.g :

      <input id="remove" type="checkbox" name="remove" value="1">
    

    In php :-

       if($checked == 1) {
          // do whatever u want
       }
    
    0 讨论(0)
  • 2021-01-13 01:33

    Try:

    <input id="remove" type="checkbox" name="remove" value="1">
    
    0 讨论(0)
  • 2021-01-13 01:35

    Use this if it can help.

    $checked = (isset($_POST['checkbox']))?true:false;
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题