module with checkbox field

I want to create a module with two fields.
1.Feature Name is text filed and 2.Plans is checkbox.
i want to show Plans as checkbox and values should taken from table 'plans' and its column name is 'planname'.

i wrote a code like this
function form_fields($values = array())
{ $this->db->select('planname'); //change this to the two main values you want to use
$query = $this->db->get();
foreach($query->result_array() as $row){
$fields = parent::form_fields($values);
$CI =& get_instance();
foreach($val as $key => $new){
foreach($new as $k => $v){
$ne[$k] =$v;
$fields['plans'] = array('type' => 'multi', 'options' => $ne);
return $fields;

but its not showing checked values in edit page.i can save but i cant show selected values in edit page.
Please advice how to add checkbox and show selected values in edit page


  • edited 1:34AM
    Are the plan checkbox values being saved to the same model or in a different model? If the same model, is it being saved as a serialized/json encoded array?
  • edited 1:34AM
    Hi admin,

    We have two modules.
    2.Plan features

    In Plans module we have two fields
    1.plan name

    In Plan features module we have two fields.
    1.feature name
    we should retrieve that 'plan name' (Plans module) as checkbox to 'plans'(Plan features module) field and store it in plan features modules.

    for feature1 we can check or select specific plan and save.

    you know plans and features structure.
    some features related with some plans

    i want to enter feature name (text field)and that feature is related to which plans(checkbox).

    Please advice
  • edited 1:34AM
    So you are associating multiple plans with each plan feature? If so, the 1.0 beta provides a has_many property you can specify in your model which will automatically create a multi select box for you to associate multiple plans with each feature. The syntax would be something like this:
    public has_many = array('plans' => 'plans_model');
    There is more documentation on creating model relationships in the 1.0 user guide:
Sign In or Register to comment.