Shaun Hogg
Shaun Hogg

Reputation: 177

Code Igniter Dynamic Checkbox

Hi I am trying to echo out check boxes, and then determine if they are checked in my controller and add them to an array if they are. I have followed a guide from SO but still having issues. Any insight much appreciated!

Controller Code:

       foreach ($content['options'] as $option) {
            $id = $option['id'];
            $checked = (isset($_POST[$id])) ? true : false;
            if ($checked == TRUE) {
                 array_push($recipientGroups, $id);
            }
       }

View Code:

foreach ($options as $option) {
     echo br(1);
     echo $option['name'];

     $checkboxattr = array(
          'name' => $option['name'],
          'value' => $option['name'],
          'id' => $option['id']
    );  //'checkbox_'.

     echo form_checkbox($checkboxattr);
     echo "<span id='total_".strtolower($option['name'])."'></span>";
    }

Upvotes: 1

Views: 1224

Answers (1)

Yagi
Yagi

Reputation: 511

The blank array you mean is from this variable $checkboxattr?

In your view, did you get the value of array variable ($options) from the controller?

If so, have you passed it from the controller ? Because I don't see any codes in your controller that pass the array to your view.

Upvotes: 2

Related Questions