【发布时间】:2018-12-14 21:54:39
【问题描述】:
在@foreach 中使用表单后按钮不起作用。关于如何在@foreach 循环中使用表单有什么建议吗?
是否可以在 laravel 刀片文件的循环中使用表单?
这是我的 laravel 刀片文件的代码。我在 foreach 中使用了表单来获取账面金额的数据。有关如何解决此问题的任何建议?
@extends('layouts.app')
@section('content')
<div class="container">
<h1>Items On Cart:</h4>
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
<table style="border-collapse: collapse;width: 100%;">
<tr style="border: 1px solid #dddddd;text-align: left;padding: 8px;font-size:20px;color: gray">
<th>Book Name</th>
<th>Author Name</th>
<th>Book Amount</th>
<th>Price</th>
<th>Action</th>
<th>Action</th>
</tr>
@foreach($cart_items as $data)
<form action="{{ route('change_item_amount',[$cart_info->id,$data->book_id]) }}" method="POST">
<tr>
<th>{{ show_books_name($data->book_id) }}</th>
<th>{{ show_books_author($data->book_id) }}</th>
<th><input type="number" name="amount" id="amount" value="{{ $data->item_amount }}"></th>
<th>{{ $data->price }} tk</th>
<th><button type="submit" class="btn btn-success">Change</button></th>
<th><a class="btn btn-success" href="{{ route('delete_book',[$cart_info->id,$data->book_id] ) }}">Delete</a></th>
</form>
@endforeach
</table>
</div>
<h2 style="padding-left:865px">Total = {{ $cart_info->total_price }} tk</h2>
</div>
</form>
</div>
</div>
</div>
@endsection
【问题讨论】:
-
你不能在
<tr>之外有<form>标签,这是无效的标记。<form>必须包裹<table>或在<td>中(不是<tr>)。 -
您已经关闭了两次表单标签。