2014-09-16 3 views
0

이 가이드를 codeigniter : http://www.quirksmode.org/dom/domform.html에 적용하여 동적 필드가있는 양식을 만들려면 모든 기능이 원활하게 작동하지만 컨트롤러의 데이터를 에코하려고 할 때 :양식에 동적으로 코드 필드를 추가하기

echo '<pre>'.print_r($this->input->post(),TRUE).'</pre>'; 

그냥보기에 추가 된 값의 마지막 그룹을 인쇄합니다.

<?php echo form_open('admin/grabar_ruta'); ?> 
    <table width="100%"> 
    <tr> 
     <td width="12%" align="right">Fuente:</td> 
     <td width="13%" align="left"><select name="fuente"> 
     <?php foreach($fuentes as $row) { echo '<option value="'.$row->id.'">'.$row->serial.'</option>'; } ?> </select></td> 
     <td width="12%" align="right">Vehículo:</td> 
     <td width="13%" align="left"><select name="vehiculo"> 
     <?php foreach($vehiculos as $row) { echo '<option value="'.$row->id.'">'.$row->placa.'</option>'; } ?> </select></td> 
     <td width="12%" align="right">Conductor:</td> 
     <td width="13%" align="left"><select name="conductor"> 
     <?php foreach($conductores as $row) { echo '<option value="'.$row->id.'">'.$row->nombre.'</option>'; } ?> </select></td> 
     <td width="12%" align="right">Fecha:</td> 
     <td width="13%" align="left"><input type="date" name="name[]"></td> 
    </tr> 
    </table> 
    <div id="readroot" > 

<table width="100%"> 
    <tr> 
     <td width="12%" align="right">Origen:</td> 
     <td width="13%" align="left"><input type="text" name="origen" size="12"></td> 
     <td width="12%" align="right">Hora Salida:</td> 
     <td width="13%" align="left"><input type="time" name="hora_salida"></td> 
     <td width="12%" align="right">Destino:</td> 
     <td width="13%" align="left"><input type="text" name="destino" size="12"></td> 
     <td width="12%" align="right">Hora Llegada:</td> 
     <td width="13%" align="left"><input type="time" name="hora_llegada"></td> 
    </tr> 
    </table> 
<input type="button" value="Eliminar" 
    onclick="this.parentNode.parentNode.removeChild(this.parentNode);" /><br /><br /> 
</div> 
    <span id="writeroot"></span> 
    <input type="button" id="moreFields" value="Añadir ruta" /> 
    <input type="submit" value="Grabar Ruta" /> 
<?php echo form_close(); ?> 

답변

0

오 나는 내 문제를 해결할 수 있습니다 난 그냥 필요 : 여기

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<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); 
} 

양식 코드 : 여기

Example

은 JS 함수이다 뷰의 동적 구성 요소에 대한 배열 이름을 사용하십시오 :

<?php echo form_open('admin/grabar_ruta'); ?> 
    <table width="100%"> 
    <tr> 
     <td width="12%" align="right">Fuente:</td> 
     <td width="13%" align="left"><select name="fuente"> 
     <?php foreach($fuentes as $row) { echo '<option value="'.$row->id.'">'.$row->serial.'</option>'; } ?> </select></td> 
     <td width="12%" align="right">Vehículo:</td> 
     <td width="13%" align="left"><select name="vehiculo"> 
     <?php foreach($vehiculos as $row) { echo '<option value="'.$row->id.'">'.$row->placa.'</option>'; } ?> </select></td> 
     <td width="12%" align="right">Conductor:</td> 
     <td width="13%" align="left"><select name="conductor"> 
     <?php foreach($conductores as $row) { echo '<option value="'.$row->id.'">'.$row->nombre.'</option>'; } ?> </select></td> 
     <td width="12%" align="right">Fecha:</td> 
     <td width="13%" align="left"><input type="date" name="fecha"></td> 
    </tr> 
    </table> 

    <div id="readroot" > 

<table width="100%"> 
    <tr> 
     <td width="12%" align="right">Origen:</td> 
     <td width="13%" align="left"><input type="text" name="origen[]" size="12"></td> 
     <td width="12%" align="right">Hora Salida:</td> 
     <td width="13%" align="left"><input type="time" name="hora_salida[]"></td> 
     <td width="12%" align="right">Destino:</td> 
     <td width="13%" align="left"><input type="text" name="destino[]" size="12"></td> 
     <td width="12%" align="right">Hora Llegada:</td> 
     <td width="13%" align="left"><input type="time" name="hora_llegada[]"></td> 
    </tr> 
    </table> 
<input type="button" value="Eliminar" 
    onclick="this.parentNode.parentNode.removeChild(this.parentNode);" /><br /><br /> 
</div> 
    <span id="writeroot"></span> 
    <input type="button" id="moreFields" value="Añadir ruta" /> 
    <input type="submit" value="Grabar Ruta" /> 
<?php echo form_close(); ?> 
관련 문제