如何与其他变量一起传递表单数据?

时间:2019-03-27 14:42:16

标签: php laravel

我有这张表格

<!-- Need to add this CSS and JS in your HTML page -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>


<script type="text/javascript">
    //This code used to initialise the table shown
    $(document).ready(function() {
        $('#example').DataTable( {
            "processing": true,
            "serverSide": true,
            "ajax": "server_processing.php"
        } );
    } );
</script>

<table id="example" class="display" style="width:100%">
    <thead>
        <tr>
            <th>Type:</th>
            <th>Description:</th>
            <th>Recorded Date:</th>
            <th>Added Date:</th>
        </tr>
    </thead>
</table>

当我单击按钮时,它会发送 <div class="row"> <div class="col-lg-8 offset-2"> <form class="form-signin" method="POST"> {{ csrf_field() }} <div class="form-label-group mt-1"> <label class="text-dark-orange" for="name">Naam</label> <input type="text" id="name" name="name" class="form-control sentje-inputfield-payment" placeholder="Vul hier uw naam in" required> </div> <div class="form-label-group mt-1"> <label class="text-dark-orange" for="note">Notitie</label> <textarea type="text" id="note" name="note" class="form-control sentje-inputfield-payment" placeholder="Vul hier eventueel een notitie in"></textarea> </div> </div> </div> <div class="row mt-5"> <div class="col-lg-8 offset-2"> <a href="{{ route('paymentrequest.preparePayment', [$paymentrequest->unique_link, $paymentrequest]) }}"><button type="submit" class="btn btn-block btn-lg sentje-button">Betalen</button></a> </form> </div> </div> 。 (我已经将该参数发送到了视图中)如何传递传递到表单中的数据?

1 个答案:

答案 0 :(得分:1)

  1. 给您的表格一个ID,并执行<a> URL的操作:

    <form action="{{ route('paymentrequest.preparePayment', [$paymentrequest->unique_link, $paymentrequest]) }}" id="my-form" class="form-signin" method="POST">
    
  2. 使用<a>button将您的type="submit"更改为form="<form-id>"

    <button type="submit" form="my-form" class="btn btn-block btn-lg sentje-button">Betalen</button>
    

使用form属性允许您关闭form标记并将按钮保持在外面,并允许您仍然提交它并使代码保持整洁。