Welcome Guest, Not a member yet? Register   Sign In
How to create IF->ELSE with input->post() with checkbox array?
#1

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 )
<input type "checkbox" name "service[]" value "$numeric_id">

// Controller
$item $this->input->post ('service'true);
if(
$item){ //Run only when submit the form
 
 if ($item == NULL) {
 
   // function if no checkbox is checked
 
   // return to the same page with redirect(current_url());
 
 }else{
 
  // function if at least one checkbox was marked
 
  // return to the same page with redirect(current_url());
 
 }
}else{
 
 //show the view with the checkboxes and submit form button


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==NULLnot work
if($item==FALSEnot work
if($item=='') or if($item==' 'not work
if(empty($item)) not work
if(!isset($item)) not work
if(!is_array($item)) or (is_array($item)) not work
foreach($item as $key) or foreach($item as $key => $valuenot work 


Any idea what's wrong?
Reply


Messages In This Thread
How to create IF->ELSE with input->post() with checkbox array? - by rubens - 09-22-2016, 05:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB