嵌套 html formBuilder 与 Laravel
Nested html formBuilder with Laravel
cart.blade.php
@extends('master')
@section('content')
<div class="container">
@if(Cart::isEmpty())
<b>The card is empty</b> <a href="/products">Shopping now</a>
@else
<table class="table table-condensed table-bordered">
<thead>
<tr>
<th>item id</th>
....
</tr>
</thead>
<tbody>
{!! Form::open(["url"=>"/pay"]) !!}
<?php $i = 0; $totalCart_price = 0; ?>
@foreach($cart_total_items as $item)
<tr>
<td>{{ $item['id'] }}</td>
....
<td>
{!! Form::open(["url"=>"/my-cart/".$item['id'], "method"=>"DELETE", "style"=>"display: inline"]) !!}
<button type="submit" class="btn btn-danger" aria-label="Left Align">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
{!! Form::close() !!}
</td>
</tr>
<?php $i++; $totalCart_price += Cart::get($item['id'])->getPriceSum(); ?>
@endforeach
</tbody>
</table>
<b>Total price: ${{ $totalCart_price }} {{ Form::hidden("total_price", $totalCart_price) }}</b>
<br><br>
{!! Form::submit('check out (paypal)', ["class"=>"btn btn-primary"]) !!}
{!! Form::close() !!}
<a href="/my-cart/clear" class="btn btn-danger">Clear cart</a>
@endif
</div>
@stop
问题: 我可以删除任何项目,但在单击检出期间没有任何反应,但是当我删除 clear item form
时,检出 运行 成功。
我想运行两次操作,请问如何解决?
谢谢
一个页面中可以有多个表单,但它们不应嵌套。
如 html5 working draft 中给出的:
4.10.3 The form element
Content model:
Flow content, but with no form element descendants.
据我所知,表单只是 html 标签,可用于一次向服务器发送一组(数组)数据。
在你的情况下,你最好的选择是使用 ajax 查询。(尽管它会使我们的页面 javascript 依赖)
或者,正如我观察到的,您可以像下面这样将两种形式分开:
@extends('master')
@section('content')
<div class="container">
@if(Cart::isEmpty())
<b>The card is empty</b> <a href="/products">Shopping now</a>
@else
<table class="table table-condensed table-bordered">
<thead>
<tr>
<th>item id</th>
....
</tr>
</thead>
<tbody>
<<!-- Remove the Form tag from here and insert it below -->>
<?php $i = 0; $totalCart_price = 0; ?>
@foreach($cart_total_items as $item)
<tr>
<td>{{ $item['id'] }}</td>
....
<td>
{!! Form::open(["url"=>"/my-cart/".$item['id'], "method"=>"DELETE", "style"=>"display: inline"]) !!}
<button type="submit" class="btn btn-danger" aria-label="Left Align">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
{!! Form::close() !!}
</td>
</tr>
<?php $i++; $totalCart_price += Cart::get($item['id'])->getPriceSum(); ?>
@endforeach
</tbody>
</table>
<<!-- Remove the Form tag from above and insert it below -->>
{!! Form::open(["url"=>"/pay"]) !!}
<b>Total price: ${{ $totalCart_price }} {{ Form::hidden("total_price", $totalCart_price) }}</b>
<br><br>
{!! Form::submit('check out (paypal)', ["class"=>"btn btn-primary"]) !!}
{!! Form::close() !!}
<a href="/my-cart/clear" class="btn btn-danger">Clear cart</a>
@endif
</div>
@stop
cart.blade.php
@extends('master')
@section('content')
<div class="container">
@if(Cart::isEmpty())
<b>The card is empty</b> <a href="/products">Shopping now</a>
@else
<table class="table table-condensed table-bordered">
<thead>
<tr>
<th>item id</th>
....
</tr>
</thead>
<tbody>
{!! Form::open(["url"=>"/pay"]) !!}
<?php $i = 0; $totalCart_price = 0; ?>
@foreach($cart_total_items as $item)
<tr>
<td>{{ $item['id'] }}</td>
....
<td>
{!! Form::open(["url"=>"/my-cart/".$item['id'], "method"=>"DELETE", "style"=>"display: inline"]) !!}
<button type="submit" class="btn btn-danger" aria-label="Left Align">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
{!! Form::close() !!}
</td>
</tr>
<?php $i++; $totalCart_price += Cart::get($item['id'])->getPriceSum(); ?>
@endforeach
</tbody>
</table>
<b>Total price: ${{ $totalCart_price }} {{ Form::hidden("total_price", $totalCart_price) }}</b>
<br><br>
{!! Form::submit('check out (paypal)', ["class"=>"btn btn-primary"]) !!}
{!! Form::close() !!}
<a href="/my-cart/clear" class="btn btn-danger">Clear cart</a>
@endif
</div>
@stop
问题: 我可以删除任何项目,但在单击检出期间没有任何反应,但是当我删除 clear item form
时,检出 运行 成功。
我想运行两次操作,请问如何解决?
谢谢
一个页面中可以有多个表单,但它们不应嵌套。
如 html5 working draft 中给出的:
4.10.3 The form element
Content model:
Flow content, but with no form element descendants.
据我所知,表单只是 html 标签,可用于一次向服务器发送一组(数组)数据。
在你的情况下,你最好的选择是使用 ajax 查询。(尽管它会使我们的页面 javascript 依赖)
或者,正如我观察到的,您可以像下面这样将两种形式分开:
@extends('master')
@section('content')
<div class="container">
@if(Cart::isEmpty())
<b>The card is empty</b> <a href="/products">Shopping now</a>
@else
<table class="table table-condensed table-bordered">
<thead>
<tr>
<th>item id</th>
....
</tr>
</thead>
<tbody>
<<!-- Remove the Form tag from here and insert it below -->>
<?php $i = 0; $totalCart_price = 0; ?>
@foreach($cart_total_items as $item)
<tr>
<td>{{ $item['id'] }}</td>
....
<td>
{!! Form::open(["url"=>"/my-cart/".$item['id'], "method"=>"DELETE", "style"=>"display: inline"]) !!}
<button type="submit" class="btn btn-danger" aria-label="Left Align">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
{!! Form::close() !!}
</td>
</tr>
<?php $i++; $totalCart_price += Cart::get($item['id'])->getPriceSum(); ?>
@endforeach
</tbody>
</table>
<<!-- Remove the Form tag from above and insert it below -->>
{!! Form::open(["url"=>"/pay"]) !!}
<b>Total price: ${{ $totalCart_price }} {{ Form::hidden("total_price", $totalCart_price) }}</b>
<br><br>
{!! Form::submit('check out (paypal)', ["class"=>"btn btn-primary"]) !!}
{!! Form::close() !!}
<a href="/my-cart/clear" class="btn btn-danger">Clear cart</a>
@endif
</div>
@stop