title: Adding fields in a form dynamically with codeigniter
body: <p>I am adapting this guide in codeigniter: <a href="http://www.quirksmode.org/dom/domform.html" rel="nofollow noreferrer">http://www.quirksmode.org/dom/domform.html</a>, in order to create a form with dynamic fields, all the functionality is working good, however when I try to echo the data in my controller with: </p>
  
  <pre><code>echo '&lt;pre&gt;'.print_r($this-&gt;input-&gt;post(),TRUE).'&lt;/pre&gt;';
  </code></pre>
  
  <p>it just print the last group of values that were added in the view.</p>
  
  <p>i.e.</p>
  
  <p><img src="https://i.stack.imgur.com/BUVyu.png" alt="Example"></p>
  
  <p>Here is the js function:</p>
  
  <pre><code>var counter = 0;
  function init() {
    document.getElementById('moreFields').onclick = moreFields;
  }
  
  function moreFields() {
    counter++;
    var newFields = document.getElementById('readroot').cloneNode(true);
    newFields.id = '';
    newFields.style.display = 'block';
    var newField = newFields.childNodes;
    for (var i=0;i&lt;newField.length;i++) {
      var theName = newField[i].name
      if (theName)
        newField[i].name = theName + counter;
    }
    var insertHere = document.getElementById('writeroot');
    insertHere.parentNode.insertBefore(newFields,insertHere);
  }
  </code></pre>
  
  <p>Here is the form code:</p>
  
  <pre><code>&lt;?php echo form_open('admin/grabar_ruta'); ?&gt;
     &lt;table width="100%"&gt;
      &lt;tr&gt;
        &lt;td width="12%" align="right"&gt;Fuente:&lt;/td&gt;
        &lt;td width="13%" align="left"&gt;&lt;select name="fuente"&gt; 
        &lt;?php foreach($fuentes as $row) { echo '&lt;option value="'.$row-&gt;id.'"&gt;'.$row-&gt;serial.'&lt;/option&gt;'; } ?&gt; &lt;/select&gt;&lt;/td&gt;
        &lt;td width="12%" align="right"&gt;Vehículo:&lt;/td&gt;
        &lt;td width="13%" align="left"&gt;&lt;select name="vehiculo"&gt; 
        &lt;?php foreach($vehiculos as $row) { echo '&lt;option value="'.$row-&gt;id.'"&gt;'.$row-&gt;placa.'&lt;/option&gt;'; } ?&gt; &lt;/select&gt;&lt;/td&gt;
        &lt;td width="12%" align="right"&gt;Conductor:&lt;/td&gt;
        &lt;td width="13%" align="left"&gt;&lt;select name="conductor"&gt; 
        &lt;?php foreach($conductores as $row) { echo '&lt;option value="'.$row-&gt;id.'"&gt;'.$row-&gt;nombre.'&lt;/option&gt;'; } ?&gt; &lt;/select&gt;&lt;/td&gt;
         &lt;td width="12%" align="right"&gt;Fecha:&lt;/td&gt;
        &lt;td width="13%" align="left"&gt;&lt;input type="date" name="name[]"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt; 
      &lt;div id="readroot" &gt;
  
  &lt;table width="100%"&gt;
      &lt;tr&gt;
        &lt;td width="12%" align="right"&gt;Origen:&lt;/td&gt;
        &lt;td width="13%" align="left"&gt;&lt;input type="text" name="origen" size="12"&gt;&lt;/td&gt;
        &lt;td width="12%" align="right"&gt;Hora Salida:&lt;/td&gt;
        &lt;td width="13%" align="left"&gt;&lt;input type="time" name="hora_salida"&gt;&lt;/td&gt;
        &lt;td width="12%" align="right"&gt;Destino:&lt;/td&gt;
        &lt;td width="13%" align="left"&gt;&lt;input type="text" name="destino" size="12"&gt;&lt;/td&gt;
         &lt;td width="12%" align="right"&gt;Hora Llegada:&lt;/td&gt;
        &lt;td width="13%" align="left"&gt;&lt;input type="time" name="hora_llegada"&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  &lt;input type="button" value="Eliminar"
      onclick="this.parentNode.parentNode.removeChild(this.parentNode);" /&gt;&lt;br /&gt;&lt;br /&gt; 
  &lt;/div&gt;
    &lt;span id="writeroot"&gt;&lt;/span&gt;
    &lt;input type="button" id="moreFields" value="Añadir ruta" /&gt;
    &lt;input type="submit" value="Grabar Ruta" /&gt;  
  &lt;?php echo form_close(); ?&gt;
  </code></pre>