samedi 9 février 2019

jQuery controls not passed to controller

I'm adding new controls in jQuery to a GET form, but when I submit the form the values are not part of the request.

Is jQuery the right tool for the job? Do I need to submit the form with jQuery instead?

enter image description here

<form method="post" action="">
...
<table id="shopsTable" class="table">
    <tr>
        <th>Winkel</th>
        <th>URL</th>
        <th>Prijs</th>
        <th></th>
        <th></th>
    </tr>
    @foreach($product->shops as $key=>$shop)
    <tr id="row">
        <td><input disabled type="text" class="form-control" name="shop[][name]" value=""</td>
        <td><input disabled type="text" class="form-control" name="shop[][url]" value=""/></td>
        <td><input disabled type="number" class="form-control" name="shop[][price]" value=""/></td>
        <td><button type="button" class="btn btn-danger">remove</button></td>
    </tr>
    @endforeach
</table>

<button type="submit" class="btn btn-success">Update product</button>

jQuery

<script type="text/javascript">
$(document).on('click', '.new-shop', function() {

    var row = $('tr[id=row]').length + 1;
    var storeName = $('#new_shop option:selected').text();
    var storeId = $('#new_shop option:selected').val();
    var url = $('#new_shop_url').val();
    var price = $('#new_shop_price').val();

    if (url.length > 0 && price.length > 0) {

        $('#shopsTable').append('<tr id="row">' +
            '<td><input disabled type="text" class="form-control" name="shop['+ row +'][name]" value="'+ storeName +'"</td>' +
            '<td><input disabled type="text" class="form-control" name="shop['+ row +'][url]" value="'+ url +'"/></td>' +
            '<td><input disabled type="number" class="form-control" name="shop['+ row +'][price]" value="'+ price +'"/></td>' +
            '<td><button type="button" class="btn btn-danger">remove</button></td>' +
        '</tr>');

        var store = $('#new_shop').val(1);
        var url = $('#new_shop_url').val('');
        var price = $('#new_shop_price').val('');

    } else {
        console.log('Gelieve alle velden in te vullen');
    }

});
</script>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire