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
$this->db->from('plans');
$query = $this->db->get();
$val=array();
foreach($query->result_array() as $row){
array_push($val,array($row['planname']=>$row['planname']));
}
$fields = parent::form_fields($values);
$CI =& get_instance();
$ne=array();
foreach($val as $key => $new){
foreach($new as $k => $v){
$ne[$k] =$v;
}
}
$fields['plans'] = array('type' => 'multi', 'options' => $ne);
$this->form_builder->create_checkbox($fields);
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
Comments
We have two modules.
1.Plans
2.Plan features
In Plans module we have two fields
1.plan name
2.price
In Plan features module we have two fields.
1.feature name
2.plans
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
public has_many = array('plans' => 'plans_model');
There is more documentation on creating model relationships in the 1.0 user guide:
https://github.com/daylightstudio/FUEL-CMS/tree/1.0
https://github.com/daylightstudio/FUEL-CMS-User-Guide-Module