我在同一页面上有三种不同的表格。所有输入都有自己的验证规则,请求文件中的代码具有如下结构:
public function rules()
{
return [
//
'sold' => 'required',
'unit_in_stock' => 'required',
'unit_price_gbp' => 'required',
'returned_item' => 'required',
];
}
public function messages()
{
return [
'sold.required' => 'Please enter quantity of sold parts',
'unit_in_stock.required' => 'Please enter quantity of sold parts',
'unit_price_gbp.required' => 'Please enter price in GBP',
'returned_item.required' => 'Please enter quantity of items',
];
}
但是,当我尝试提交三个表单之一时,另一个表单返回有关空字段的消息。这种形式彼此不相关。
这是我的表格:
{!! Form::open(['url' => route('addDelivery.addDelivery'),'class'=>'contact-form','method'=>'POST']) !!}
<label>Price in GBP £:</label>
{!! Form::text('unit_price_gbp', isset($price->unit_price_gbp) ? $price->unit_price_gbp : old('unit_price_gbp'), array('class'=>'form-control'), ['placeholder'=>'GBP']) !!}
<label>Quantity: </label>
{!! Form::text('unit_in_stock', isset($price->unit_in_stock) ? $price->unit_in_stock : old('unit_in_stock'), array('class'=>'form-control'), ['placeholder'=>'Qt.']) !!}
<input type="hidden" name="part_number" value="{{ $product->part_number }}">
<input type="hidden" name="part_id" value="{{ $product->id }}">
<input type="hidden" name="slug" value="{{ $product->slug }}">
{!! Form::button('Add Delivery', ['class' => 'btn btn-sm btn-success','type'=>'submit']) !!}
{!! Form::close() !!}
{!! Form::open(['url' => route('sold.sold'),'class'=>'contact-form','method'=>'POST']) !!}
<label style="margin-right: 30px;">Sell:</label>
{!! Form::text('sold', old('sold'), array('class'=>'form-control', 'placeholder'=>'Qty.')) !!}
<input type="hidden" name="part_id" value="{{ $product->id }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
{!! Form::button('Sold', ['class' => 'btn btn-sm btn-success','type'=>'submit']) !!}
{!! Form::close() !!}
{!! Form::open(['url' => route('productReturn.productReturn'),'class'=>'contact-form','method'=>'POST']) !!}
<label>Return:</label>
{!! Form::text('returned_item', old('returned_item'), array('class'=>'form-control', 'placeholder'=>'Qty.')) !!}
<input type="hidden" name="part_id" value="{{ $product->id }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
{!! Form::button('Return', ['class' => 'btn btn-sm btn-success','type'=>'submit']) !!}
{!! Form::close() !!}
但是这三个表格都是分开的,需要单独提交。
我该如何解决这个问题?