title: Dynamic checkbox and get the values from the checkbox checked
body: <p>I am having difficulty creating dynamic checkboxes from db, and getting the values from the checkboxes when checked.</p>
  
  <p>I have this Controller: </p>
  
  <pre><code>public function proporEvento(){
  
      $natureza = $this-&gt;evento_model-&gt;naturezaEvento();
      $apoio = $this-&gt;evento_model-&gt;apoioPertendido();
      $espaco = $this-&gt;evento_model-&gt;espaco();
      $material = $this-&gt;evento_model-&gt;material();
      $suportgraf = $this-&gt;evento_model-&gt;suporteGrafico();
      $audiovisual = $this-&gt;evento_model-&gt;audioVisual();                  
  
      $data['title']              = 'Propor Evento';
      $data['naturezaEvento']     = $natureza;
      $data['apoioPertendido']    = $apoio;
      $data['espaco']             = $espaco;
      $data['material']           = $material;
      $data['suporteGraf']        = $suportgraf;
      $data['audioVisual']        = $audiovisual;
  
  
  
      $this-&gt;load-&gt;view('cliente/clienteheaderdash_view', $data);
      $this-&gt;load-&gt;view('cliente/clientemenu_view', $data);
      $this-&gt;load-&gt;view('cliente/clienteproporevento_view', $data);
      $this-&gt;load-&gt;view('cliente/clientefooterdash_view', $data);
  }
  </code></pre>
  
  <p>Have this model:</p>
  
  <pre><code>public function naturezaEvento(){
      $query = $this-&gt;db-&gt;get('tblnaturezaevento');       
      return $query-&gt;result(); 
  }
  
  public function apoioPertendido(){      
      $query = $this-&gt;db-&gt;get('tblapoio');        
      return $query-&gt;result();
  }
  
  public function espaco(){
      $query = $this-&gt;db-&gt;get('tblespaco');       
      return $query-&gt;result();
  }
  
  public function material(){
      $query = $this-&gt;db-&gt;get('tblmaterial');     
      return $query-&gt;result();
  }
  
  public function suporteGrafico(){
      $query = $this-&gt;db-&gt;get('tblsuportegraf');      
      return $query-&gt;result();
  }
  
  
  public function audioVisual(){
      $query = $this-&gt;db-&gt;get('tblaudiovisual');      
      return $query-&gt;result();
  }
  </code></pre>
  
  <p>...and I have this view (one part for example):</p>
  
  <pre><code>&lt;label&gt;Apoio Pertendido&lt;/label&gt;
  &lt;div class="form-group"&gt;
       &lt;?php foreach ($apoioPertendido as $row) { ?&gt;
       &lt;label&gt;
        &lt;input type="checkbox" class="flat-red" name="apoiopretendido[]" value="&lt;?php   echo $row-&gt;idApoio  ?&gt;" /&gt; &lt;?php   echo $row-&gt;descricao;  ?&gt;
         &lt;/label&gt;
         &lt;/br&gt;
      &lt;?php }  ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>this code create the <code>&lt;input type="checkbox"...&gt;</code> correctly but how can I get the values from checked checkbox?</p>
  
  <p>My form to go with this controller function:</p>
  
  <pre><code> public function etapa2(){
      //$this-&gt;load-&gt;library('form_validation');
  
      // $this-&gt;form_validation-&gt;set_rules('naturezaEvento', 'naturezaEvento', '|required|');
      //$this-&gt;form_validation-&gt;set_rules('denominacao', 'denominacao', '|required|');
      // $this-&gt;form_validation-&gt;set_rules('datainicio', 'datainicio', '|required|');
      // $this-&gt;form_validation-&gt;set_rules('horainicio', 'horainicio', '|required|');
      // $this-&gt;form_validation-&gt;set_rules('datafim', 'datafim', '|required|');
      // $this-&gt;form_validation-&gt;set_rules('datainicio', 'datainicio', '|required|');
  
      //if($this-&gt;form_validation-&gt;run() == FALSE){
          //$this-&gt;index();
          //}else{
  
      $datageral['idcliente'] = $this-&gt;session-&gt;userdata('idcliente');
      $datageral['idnatureza']=$this-&gt;input-&gt;post('naturezaEvento'); //insere o id do campo natureza da tabela tblnaturezaevento
      $datageral['denominacaotitulo'] =  $this-&gt;input-&gt;post('denominacao'); 
      $datageral['datainicio']=$this-&gt;input-&gt;post('datainicio');
      $datageral['horainicio']=$this-&gt;input-&gt;post('horainicio');
      $datageral['datafim']=$this-&gt;input-&gt;post('datafim');
      $datageral['horafim']=$this-&gt;input-&gt;post('horafim');
      $datageral['planotrabalho']=$this-&gt;input-&gt;post('planotrabalho');
      $datageral['raidertecnico']=$this-&gt;input-&gt;post('raidertecnico');
      $datageral['programa']=$this-&gt;input-&gt;post('programa');
      $datageral['mesa']=$this-&gt;input-&gt;post('mesa');
      $datageral['notas']=$this-&gt;input-&gt;post('notas');
      //'valorprovisorio' =&gt; $this-&gt;input-&gt;post('notas'), TODO fazer o valor provisório
  
      //checkbox apoio
      $apoiopertendido = $this-&gt;evento_model-&gt;apoioPertendido();           
      foreach ($apoiopertendido as $row) {
          if ($this-&gt;input-&gt;post($row-&gt;checked, TRUE)===true){
              $datageral[$row-&gt;tag] = $this-&gt;input-&gt;post($row-&gt;tag);
              }
      }
  
       //checkbox espaços
      $espacopertendido = $this-&gt;evento_model-&gt;espaco();
      //$esp = array();
      foreach ($espacopertendido as $row) {
          if ($this-&gt;input-&gt;post($row-&gt;tag, TRUE)===true){
              $datageral[$row-&gt;tag] = $this-&gt;input-&gt;post($row-&gt;tag);
          }
      }
  
      //Material Necessário
      $material = $this-&gt;evento_model-&gt;material();
      //$materialnecessario = array();
      foreach ($material as $row) {           
          $datageral[$row-&gt;tag] = $this-&gt;input-&gt;post($row-&gt;tag);            
      }
  
      //checkbox suportes graficos
      $suporteGrafico = $this-&gt;evento_model-&gt;suporteGrafico();
      //$suporte = array();
      foreach ($suporteGrafico as $row) {
          if ($this-&gt;input-&gt;post($row-&gt;tag, TRUE)===true){
              $datageral[$row-&gt;tag] = $this-&gt;input-&gt;post($row-&gt;tag);
          }
      }
  
      //Registo Audio Visual
      $audioVisual = $this-&gt;evento_model-&gt;audioVisual();
      //$audiov = array();
      foreach ($audioVisual as $row) {
          if ($this-&gt;input-&gt;post($row-&gt;tag, TRUE)===true){
              $datageral[$row-&gt;tag] = $this-&gt;input-&gt;post($row-&gt;tag);
          }
      }
  
      $this-&gt;load-&gt;view('cliente/clienteheaderdash_view');
      $this-&gt;load-&gt;view('cliente/clientemenu_view');     
      $this-&gt;load-&gt;view('cliente/clienteetapa2_view', $datageral);
      $this-&gt;load-&gt;view('cliente/clientefooterdash_view');
             // }
  }
  </code></pre>