动态表单未发送所有值

时间:2018-07-03 03:48:21

标签: javascript php arrays laravel

我有一个表单,可以使用Javascript动态添加,并且可以正常工作;但是,当我将值发送给控制器时,我仅从最后填写的表单中获取数据,不知道为什么。 我正在使用laravel 5.4。

编辑: 我放置孔视图代码是为了以防万一我看不到某些东西,也许其他人会看到。 谢谢进阶

{!! Form::open(array('route' => 'items.store', 'method' => 'POST'), array('role' => 'form')) !!}
<div class="input-group control-group after-add-more"  id="formulario">
<div class="row">
<div class="form-group">
  {!! Form::label('cantidad[]', 'Cantidad') !!}
  {!! Form::text('cantidad[]', null, array('placeholder' => 'Ingresa cantidad del item', 'class' => 'form-control')) !!}
</div>
<div class="form-group">
  {!! Form::label('detalle[]', 'Detalle') !!}
  {!! Form::text('detalle[]', null, array('placeholder' => 'Ingresa detalle del artículo', 'class' => 'form-control')) !!}
</div>
<div class="form-group">
  {!! Form::label('unidad[]', 'Unidad') !!}
  {!! Form::text('unidad[]', null, array('placeholder' => 'Ingresa la unidad de medida (cm, m, kg; etc)', 'class' => 'form-control')) !!}
</div>
<div class="form-group">
  {!! Form::label('unitario[]', 'Unitario') !!}
  {!! Form::text('unitario[]', null, array('placeholder' => 'Indica el valor unitario del item', 'class' => 'form-control')) !!}
</div>

    {!! Form :: button('Guardar',array('type'=>'submit','class'=>'btn btn-primary'))!!}
    {!!形式:: close()!!}

 <div class="form-group hide" id="cloneMe">
  <div class="form-group">
  {!! Form::label('cantidad', 'Cantidad') !!}
  {!! Form::text('cantidad', null, array('placeholder' => 'Ingresa cantidad 
del item', 'class' => 'form-control')) !!}
</div>
<div class="form-group">
  {!! Form::label('detalle', 'Detalle') !!}
  {!! Form::text('detalle', null, array('placeholder' => 'Ingresa detalle del artículo', 'class' => 'form-control')) !!}
</div>
<div class="form-group">
  {!! Form::label('unidad', 'Unidad') !!}
  {!! Form::text('unidad', null, array('placeholder' => 'Ingresa la unidad de medida (cm, m, kg; etc)', 'class' => 'form-control')) !!}
</div>
<div class="form-group">
  {!! Form::label('unitario', 'Unitario') !!}
  {!! Form::text('unitario', null, array('placeholder' => 'Indica el valor unitario del item', 'class' => 'form-control')) !!}
</div>
<button class="btn btn-primary" value="borrame">Borrar</button>

<script type="text/javascript">
$(document).ready(function() {
var max_fields      = 10; //maximum input boxes allowed
var wrapper         = $("#formulario"); //Fields wrapper
var add_button      = $("#botoncito"); //Add button ID

var x = 1; //initlal text box count
$(add_button).click(function(e){ //on add input button click
    e.preventDefault();
    if(x < max_fields){ //max input box allowed
        x++; //text box increment
        var cloneHtml = $('#cloneMe').html();
        $(wrapper).append(cloneHtml); //add input box
    }
});

$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
    e.preventDefault(); $(this).parent('div').remove(); x--;
})
});

0 个答案:

没有答案