单击表单提交按钮时如何更改php值(Laravel)

时间:2020-10-14 08:02:38

标签: php laravel

这是我的代码:

@php
   $id = 1;
@endphp

<form action="{{route('upload.submit_rencana_kerja_bulanan',$id)}}" method="post">
{{ csrf_field() }}
<!-- Begin body content -->
<div class="card-body">
    {{-- TABLE --}}
    <!-- Begin body content -->
    <div class="table-responsive">
        <table data-toggle="table" data-height="460" data-width="600" data-search="true" data-visible-search="true" data-show-columns="true"
            data-show-footer="false">
            <thead>
                <tr>
                    <th data-sortable="true">Nomor</th>
                    <th data-sortable="true">ID</th>
                    <th data-sortable="true">Customer</th>
                    <th data-sortable="true">Outlet</th>

                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                @foreach ($masterCustomer as $masterCustomers)
                    <tr>
                        <td>{{$nomorTable2}}</td>
                        <td>{{$masterCustomers->id}}</td>
                        <td>{{$masterCustomers->customer_name}}</td>
                        <td>{{$masterCustomers->customer_outlet}}</td>

                        <td class="text-center">
                            <a href="{{url('add_customer/'. $masterCustomers->id . '/' . $emp_name . '/' . $date . '/rencana_kerja_bulanan')}}">
                                <button class="btn btn-success" type="submit">
                                    Add
                                </button>
                            </a>
                        </td>
                    </tr>

                    @php
                        $nomorTable2++;
                    @endphp
                @endforeach

            </tbody>
        </table>
    <!-- end of body content -->
    </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>

                {{-- <button id="btnsubmit" class="btn btn-success" type="submit">
                    Submit Data
                </button> --}}
            </div>
        </div>
        </div>
    </div>
    {{-- SAMPAI SINI MODALNYA --}}
</div>
</form>

我要更改$ id = 1;点击表格中的按钮后,用户将在表格中选择的值

您可以通过此方法更改值吗?

不能添加更多代码,因为stackoverflow不允许我这样做,所以要添加很多代码

1 个答案:

答案 0 :(得分:2)

您无法使用javascript更改PHP值。我认为您可以在表单中使用隐藏字段,并在单击按钮时更改隐藏字段的值。表单发布后,您可以从该隐藏字段中获取ID的值。

相关问题