Advertisement
cdsatrian

checkbox warna

Feb 21st, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.57 KB | None | 0 0
  1. //Ini form inputnya    
  2.  <div class="form-group">
  3.         <label>Warna :</label>
  4.         <?php
  5.         $list_warna=array('Hitam','Merah','Kuning','Hijau');
  6.         foreach($list_warna as $w):
  7.         ?>
  8.         <div class="checkbox">
  9.           <label>
  10.             <input type="checkbox" name="warna[]" value="<?=$w?>">
  11.             <?=$w?>
  12.           </label>
  13.         </div>
  14.         <?php endforeach;?>
  15.         <div class="checkbox">
  16.           <label>
  17.             <input type="checkbox" />
  18.             <input type="text" name="warna[]" />
  19.           </label>
  20.         </div>
  21. </div>
  22.  
  23. //Ini proses di serversidenya
  24. function create(){
  25.         $data_post = $this->input->post();
  26.         foreach($data_post as $key=>$value){
  27.             if(is_array($value)){
  28.                 //ini fungsi implodenya
  29.                 $data_to_save[$key] = implode("|",array_filter($value));
  30.             }else{
  31.                 $data_to_save[$key] = $value;
  32.             }
  33.            
  34.         }
  35.     }
  36.  
  37.  
  38. //ini form editnya
  39.  <div class="form-group">
  40.         <label>Warna :</label>
  41.         <?php
  42.         $list_warna=array('Hitam','Merah','Kuning','Hijau');
  43.         $array_warna=explode('|',$warna);
  44.         $diff=array_diff($array_warna,$list_warna);
  45.         foreach($list_warna as $w):
  46.         ?>
  47.         <div class="checkbox">
  48.           <label>
  49.             <input type="checkbox" name="warna[]" value="<?=$w?>"<?=in_array($w,$array_warna)?" checked":""?>>
  50.             <?=$w?>
  51.           </label>
  52.         </div>
  53.         <?php endforeach;?>
  54.         <div class="checkbox">
  55.           <label>
  56.             <input type="checkbox" <?=!empty($diff)?' checked':''?>/>
  57.             <input type="text" name="warna[]" <?=!empty($diff)?'value="'.implode('',$diff).'"':''?>/>
  58.           </label>
  59.         </div>
  60. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement