Laravel 5.2 @foreach 内的表单
Laravel 5.2 Form inside a @foreach
我尝试将表单放入 foreach 循环中。代码是:
@foreach( $document_rows as $row )
<?php
$idx = $row->id;
$product = Product::find( $row->product_id );
$vat = Vat::find( $row->vat_id );
$tot_riga = floatval($row->price) * intval($row->product_quantity);
?>
{!! Form::open([
'method' => 'PUT',
'route' => [ 'document.row.update', $document->id, $row->id ],
'class' => 'form-horizontal',
]) !!}
<tr class="document_row">
<td
id="field_id-{{ $idx }}"
readonly="true"
data-field="id"
data-id="{{ $idx }}"
>
{{ $idx }}
</td>
<td
class="field"
id="field_name-{{$idx}}"
data-field="name"
data-id="{{ $idx }}"
>
{{ $row->product_name }}
</td>
<td
class="field"
id="field_um-{{$idx}}"
data-field="um"
data-id="{{ $idx }}"
>
{{ $row->product_um }}
</td>
<td
class="field"
id="field_quantity-{{ $idx }}"
data-field="quantity"
data-id="{{ $idx }}"
>
{{ $row->product_quantity }}
</td>
<td
class="field"
id="field_price-{{ $idx }}"
data-field="price"
data-id="{{ $idx }}"
>
{{ $row->price }}
</td>
<td
class="field"
id="field_vat-{{ $idx }}"
data-field="vat"
data-id="{{ $idx }}"
>
{{ $vat->name }}
</td>
<td
class="field"
id="field_price_inc_vat-{{ $idx }}"
data-field="price_inc_vat"
data-id="{{ $idx }}"
>
{{ $row->price_inc_vat }}
</td>
<td
id="field_tot_riga-{{ $idx }}"
readonly="true"
data-field="tot_riga"
data-id="{{ $idx }}"
>
{{ $tot_riga }}
</td>
</tr>
{!! Form::close() !!}
@endforeach
问题是表单标签立即关闭:
<form method="POST" action="http://localhost:8888/site/public/document/1/row/update/1" accept-charset="UTF-8" class="form-horizontal"></form><input name="_method" type="hidden" value="PUT"><input name="_token" type="hidden" value="62PHHV4cnYmVOVQkkV43UCWdTkbE3tpo0OIUxuCx">
<tr class="document_row">
<td id="field_id-1" readonly="true" data-field="id" data-id="1" tabindex="1">1</td>
<td class="field" id="field_name-1" data-field="name" data-id="1" tabindex="1"></td>
<td class="field" id="field_um-1" data-field="um" data-id="1" tabindex="1">nr</td>
<td class="field" id="field_quantity-1" data-field="quantity" data-id="1" tabindex="1">100</td>
<td class="field" id="field_price-1" data-field="price" data-id="1" tabindex="1">13</td>
<td class="field" id="field_vat-1" data-field="vat" data-id="1" tabindex="1">Iva 22%</td>
<td class="field" id="field_price_inc_vat-1" data-field="price_inc_vat" data-id="1" tabindex="1">15</td>
<td id="field_tot_riga-1" readonly="true" data-field="tot_riga" data-id="1" tabindex="1">1300</td>
</tr>
有人可以帮助我吗?
您不能将表格放在内部 table。
试试这个。
<form>
@foreach()
<table> .... </table>
@endforeach
</form>
注意:浏览器操纵 html 标签。
我尝试将表单放入 foreach 循环中。代码是:
@foreach( $document_rows as $row )
<?php
$idx = $row->id;
$product = Product::find( $row->product_id );
$vat = Vat::find( $row->vat_id );
$tot_riga = floatval($row->price) * intval($row->product_quantity);
?>
{!! Form::open([
'method' => 'PUT',
'route' => [ 'document.row.update', $document->id, $row->id ],
'class' => 'form-horizontal',
]) !!}
<tr class="document_row">
<td
id="field_id-{{ $idx }}"
readonly="true"
data-field="id"
data-id="{{ $idx }}"
>
{{ $idx }}
</td>
<td
class="field"
id="field_name-{{$idx}}"
data-field="name"
data-id="{{ $idx }}"
>
{{ $row->product_name }}
</td>
<td
class="field"
id="field_um-{{$idx}}"
data-field="um"
data-id="{{ $idx }}"
>
{{ $row->product_um }}
</td>
<td
class="field"
id="field_quantity-{{ $idx }}"
data-field="quantity"
data-id="{{ $idx }}"
>
{{ $row->product_quantity }}
</td>
<td
class="field"
id="field_price-{{ $idx }}"
data-field="price"
data-id="{{ $idx }}"
>
{{ $row->price }}
</td>
<td
class="field"
id="field_vat-{{ $idx }}"
data-field="vat"
data-id="{{ $idx }}"
>
{{ $vat->name }}
</td>
<td
class="field"
id="field_price_inc_vat-{{ $idx }}"
data-field="price_inc_vat"
data-id="{{ $idx }}"
>
{{ $row->price_inc_vat }}
</td>
<td
id="field_tot_riga-{{ $idx }}"
readonly="true"
data-field="tot_riga"
data-id="{{ $idx }}"
>
{{ $tot_riga }}
</td>
</tr>
{!! Form::close() !!}
@endforeach
问题是表单标签立即关闭:
<form method="POST" action="http://localhost:8888/site/public/document/1/row/update/1" accept-charset="UTF-8" class="form-horizontal"></form><input name="_method" type="hidden" value="PUT"><input name="_token" type="hidden" value="62PHHV4cnYmVOVQkkV43UCWdTkbE3tpo0OIUxuCx">
<tr class="document_row">
<td id="field_id-1" readonly="true" data-field="id" data-id="1" tabindex="1">1</td>
<td class="field" id="field_name-1" data-field="name" data-id="1" tabindex="1"></td>
<td class="field" id="field_um-1" data-field="um" data-id="1" tabindex="1">nr</td>
<td class="field" id="field_quantity-1" data-field="quantity" data-id="1" tabindex="1">100</td>
<td class="field" id="field_price-1" data-field="price" data-id="1" tabindex="1">13</td>
<td class="field" id="field_vat-1" data-field="vat" data-id="1" tabindex="1">Iva 22%</td>
<td class="field" id="field_price_inc_vat-1" data-field="price_inc_vat" data-id="1" tabindex="1">15</td>
<td id="field_tot_riga-1" readonly="true" data-field="tot_riga" data-id="1" tabindex="1">1300</td>
</tr>
有人可以帮助我吗?
您不能将表格放在内部 table。 试试这个。
<form>
@foreach()
<table> .... </table>
@endforeach
</form>
注意:浏览器操纵 html 标签。