Anu
Anu

Reputation: 630

How to work with dynamic checkboxes?

I am using code igniter. For employee i need to select possible services they can perform.i have a field service limitation where i need to store many service id that the employee can perform. my view file where i have service list is

<div class="container top">

      <ul class="breadcrumb">
         <li>
          <a href="http://localhost/elfanto/elfanto_billing/admin/employee">
            Admin          </a> 
          <span class="divider">/</span>
        </li>
        <li class="active">
          Service        </li>
      </ul>


     <div class="row">
        <div class="span12 columns">
          <div >

            <?php

            $attributes = array('class' => 'form-inline reset-margin', 'id' => 'myform');

            $options_manufacture = array(0 => "all");
            foreach ($category as $row)
            {
              $options_manufacture[$row['id']] = $row['name'];
            }
            //save the columns names in a array that we will use as filter         
            $options_products = array();    
            foreach ($service as $array) {
              foreach ($array as $key => $value) {
                $options_products[$key] = $key;
              }
              break;
            }
 echo form_open('admin/employee', $attributes);

            ?>

          </div>

          <table class="table table-striped table-bordered table-condensed">
            <thead>
              <tr>
                <th class="header">Service id</th>
                <th class="yellow header headerSortDown">Service name </th>
                <th class="green header">Service catogary</th>
                <th class="red header">Service tax</th>
                <th class="red header">Service length</th>
                <th class="red header">Service price</th>
                <th class="red header">Actions</th>
              </tr>
            </thead>
            <tbody>
              <?php
              foreach($service as $row)
              {
                echo '<tr>';
                echo '<td>'.$row['id'].'</td>';
                echo '<td>'.$row['service_name'].'</td>';
                echo '<td>'.$row['category'].'</td>';
                echo '<td>'.$row['service_tax'].'</td>';
                echo '<td>'.$row['service_length'].'</td>';
                echo '<td>'.$row['service_price'].'</td>';
                echo '<td class="crud-actions">
                 <input type="checkbox" value=""/>

                </td>';
                echo '</tr>';
              }
              ?>      
            </tbody>
          </table>

          <?php echo '<div class="pagination">'.$this->pagination->create_links().'</div>'; ?>

      </div>
    </div>
    <div>
    <button class="btn btn-primary" type="submit">Save changes</button>
            <button class="btn" type="reset">Cancel</button>
    </div>
      <?php echo form_close(); ?>

here i have multiple check boxes when i choose the check box i need to get the id value and update the employee service limitation field with 4 or more id

Upvotes: 0

Views: 354

Answers (1)

Sougata Bose
Sougata Bose

Reputation: 31739

You can use input arrays -

<input type="checkbox" value="'.$row['id'].'" name="services[]"/>

And store it in database as json string.

Upvotes: 1

Related Questions