How to create IF->ELSE with input->post() with checkbox array? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: How to create IF->ELSE with input->post() with checkbox array? (/showthread.php?tid=66222) |
How to create IF->ELSE with input->post() with checkbox array? - rubens - 09-22-2016 Hi guys. I have a form that has several checkbox with the same "name" attribute. I'm trying to do a conditional to know if any checkbox is checked or not, but I can not make it work. See how it is: PHP Code: // View (have foreach checkboxes with the name 'service[]', no other input/select/etc ) The problem is that when i don't select any checkbox the input->post("service") is not NULL, not as empty or equals "" (empty). PHP Code: if($item==NULL) not work Any idea what's wrong? RE: How to create IF->ELSE with input->post() with checkbox array? - Wouter60 - 09-23-2016 PHP Code: if($item){ //Run only when submit the form This will never work. If you haven't selected any checkbox, $item will be empty, so the line with "if ($item == NULL) {" will not be executed. I assume that your form has a submit button, probably with the name "submit". PHP Code: $submit = $this->input->post('submit'); RE: How to create IF->ELSE with input->post() with checkbox array? - rubens - 09-23-2016 (09-23-2016, 03:51 AM)Wouter60 Wrote: Thanks man, this work fine to me. |