Send several input with the same name or id - Laravel Ajax

0

I want to send several input values that have the same name through a POST with Ajax. I do not know if you let me understand, but what I want is to create a detail of purchases.

My form is as follows:

<form class="form-horizontal" role="form"> 
    <input type="date" class="form-control" id="facordada_add">
    <input type="date" class="form-control" id="facordada_add">
    <input type="date" class="form-control" id="facordada_add">
</form>

My Script:

$(document).on('click', '.add-modal', function() {
        $('#addModal').modal('show');
    });

    $('.modal-footer').on('click', '.add', function() {
        $.ajax({
            type: 'POST',
            url: 'gestion-pedidos',
            data:{ 
                'data': $("modal-footer").serialize(),
                '_token': $('input[name=_token]').val(),
            },
            success: function(data) {

            },
            error: function(data) {
            },
        });
    });
    
asked by Anddy Cabrera Garcia 26.09.2017 в 04:29
source

1 answer

2

The id should always be unique, what you can do is send an array with the attributes name , which is the common practice in this case:

<form class="form-horizontal" role="form"> 
    <input type="date" class="form-control" name="facordada_add[]">
    <input type="date" class="form-control" name="facordada_add[]">
    <input type="date" class="form-control" name="facordada_add[]">
</form>

At the moment of receiving the information, you would see it in this way in php (although you will probably receive it in json format):

Array ( [facordada_add] => Array ( [0] => 2017-12-23 [1] => 1990-01-01 [2] => 1985-08-20 ) )
    
answered by 26.09.2017 в 05:38