Foreach does not record multivets

0

I'm using Codeigniter and I'm going through input[] , for this I have the button where I add the inputs

function add_fields() {
           var d = document.getElementById("content");
           d.innerHTML += "<br />  <input type='text' name='id_tecnico[]'  value=''  placeholder='Codigo' class='form-control'>";
           contar();
        }
        
        function contar (){
          var inputs = $('input[name^=id_tecnico]');
          var count = inputs.length;
          alert(count);
        }
    
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> 
<div id="content">
   <input type="text" name="id_tecnico[]"  value=""  placeholder="Codigo" >
 </div>
   <input type="button" id="more_fields" class="btn btn-primary" onclick="add_fields();" value="Otro" />

This is my Controller.

$id_detalle = $this->seguimiento->create('tabla1', $data2);
    foreach ($this->input->post('id_tecnico') as $tecnico ) {

                     $data3 = array(
                         'id_tecnico' => $tecnico,
                         'id_detalle' => $id_detalle
                     );

              $this->seguimiento->create('tabla2', $data3);

                }

model

  public function create($table, $data)
    {
        $query = $this->db->insert($table, $data);
        return $this->db->insert_id();
    }

The strange thing is that if I enter the inputs[] manually it works very well. I hope you have explained me well.

    
asked by MoteCL 18.07.2018 в 22:34
source

0 answers