Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Ini form inputnya
- <div class="form-group">
- <label>Warna :</label>
- <?php
- $list_warna=array('Hitam','Merah','Kuning','Hijau');
- foreach($list_warna as $w):
- ?>
- <div class="checkbox">
- <label>
- <input type="checkbox" name="warna[]" value="<?=$w?>">
- <?=$w?>
- </label>
- </div>
- <?php endforeach;?>
- <div class="checkbox">
- <label>
- <input type="checkbox" />
- <input type="text" name="warna[]" />
- </label>
- </div>
- </div>
- //Ini proses di serversidenya
- function create(){
- $data_post = $this->input->post();
- foreach($data_post as $key=>$value){
- if(is_array($value)){
- //ini fungsi implodenya
- $data_to_save[$key] = implode("|",array_filter($value));
- }else{
- $data_to_save[$key] = $value;
- }
- }
- }
- //ini form editnya
- <div class="form-group">
- <label>Warna :</label>
- <?php
- $list_warna=array('Hitam','Merah','Kuning','Hijau');
- $array_warna=explode('|',$warna);
- $diff=array_diff($array_warna,$list_warna);
- foreach($list_warna as $w):
- ?>
- <div class="checkbox">
- <label>
- <input type="checkbox" name="warna[]" value="<?=$w?>"<?=in_array($w,$array_warna)?" checked":""?>>
- <?=$w?>
- </label>
- </div>
- <?php endforeach;?>
- <div class="checkbox">
- <label>
- <input type="checkbox" <?=!empty($diff)?' checked':''?>/>
- <input type="text" name="warna[]" <?=!empty($diff)?'value="'.implode('',$diff).'"':''?>/>
- </label>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement