Dynamic form not sending all values


Dynamic form not sending all values



I have a form and I can add more dynamically by using Javascript, and that is working; but when I send the value to the controller I only get the data from the last filled form and have no idea why.
I am using laravel 5.4.



EDIT:
I'm putting the hole view code just in case there is something I am not seeing and maybe someone else will.
Thanks in advanced


{!! Form::open(array('route' => 'items.store', 'method' => 'POST'), array('role' => 'form')) !!}




{!! Form::label('cantidad', 'Cantidad') !!}
{!! Form::text('cantidad', null, array('placeholder' => 'Ingresa cantidad del item', 'class' => 'form-control')) !!}


{!! Form::label('detalle', 'Detalle') !!}
{!! Form::text('detalle', null, array('placeholder' => 'Ingresa detalle del artículo', 'class' => 'form-control')) !!}


{!! Form::label('unidad', 'Unidad') !!}
{!! Form::text('unidad', null, array('placeholder' => 'Ingresa la unidad de medida (cm, m, kg; etc)', 'class' => 'form-control')) !!}


{!! Form::label('unitario', 'Unitario') !!}
{!! Form::text('unitario', null, array('placeholder' => 'Indica el valor unitario del item', 'class' => 'form-control')) !!}





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




{!! Form::label('cantidad', 'Cantidad') !!}
{!! Form::text('cantidad', null, array('placeholder' => 'Ingresa cantidad
del item', 'class' => 'form-control')) !!}


{!! Form::label('detalle', 'Detalle') !!}
{!! Form::text('detalle', null, array('placeholder' => 'Ingresa detalle del artículo', 'class' => 'form-control')) !!}


{!! Form::label('unidad', 'Unidad') !!}
{!! Form::text('unidad', null, array('placeholder' => 'Ingresa la unidad de medida (cm, m, kg; etc)', 'class' => 'form-control')) !!}


{!! Form::label('unitario', 'Unitario') !!}
{!! Form::text('unitario', null, array('placeholder' => 'Indica el valor unitario del item', 'class' => 'form-control')) !!}

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







How about you share some code? We can't solve the problems we can't see. Where do you preform the form submission?
– Matt Clark
Jul 3 at 3:49





I was trying to add the code and my internet conection died :'(
– nbravos
Jul 3 at 3:55





Seems #formulario is not closed #cloneme is not closed too. In your cloneme container the fields have the same name as the other, but not as array... i think so it posts only the last ones.
– IFR
Jul 3 at 6:04






It is closed, right after the submit button. Please correct me if i'm wrong, but i thought that the clone me should have the same name given it is the same form basically, but not an array since is a single one (?)
– nbravos
Jul 4 at 4:03










By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

JMeter fails on beanshell imports

Why in node-red my HTTP POST no receive payload from inject?

PHP contact form sending but not receiving emails