请我有一个没有提交的表格,它重定向到主页,我检查了我的控制器,但是没有任何重定向到主页的表格,很奇怪,我在此页面中有两个表格,第一个提交,第二个没有,请帮助我
这是我的代码,第一种形式的代码
<form class="form-horizontal" role="form" action="" method="post" id="form1" enctype="multipart/form-data">
<div class="col-md-4">
<a class="btn btn-warning btn-sm" href="{{ URL::previous() }}">Back</a><br>
@php
$getBalance = (int) $getBalance;
$old = (int) old('totalamount');
@endphp
<label class="control-label"><small>Enter Sum Total Amount if making part payment</small></label>
<input type="text" class="form-control" readonly id="totalamount" value="{{number_format(($getBalance) ? $getBalance : $old)}}" name="totalamount" placeholder="Enter total amount (Optional)" >
<input type="hidden" name="selectedid" value="{{ $selected }}">
</div>
<div class="col-md-4">
<label class="control-label">  </label><br>
<button class="btn btn-info btn-xs " onclick="return viewInstruct('{{$instructions}}')" >Read Instruction</button>
@php
$path = base_path('../'). env('UPLOAD_PATH', '') .'/' . $sel_id.'.'.$file_ex;
@endphp
@if($sel_id != "")
@if(file_exists($path))
<a class="btn btn-primary btn-xs " target="blank" href="/pro/file/{{$sel_id.'.'.$file_ex}}" >Download file</a>
@endif
@endif
</div>
<div class="col-md-4">
<label class="control-label">Contract type</label>
<input type="text" id="contracttype1" name="contracttype1" value="{{($staticcontr->contractType) ? $staticcontr->contractType : old('contracttype1')}}" readonly="" class="form-control">
</div>
<div class="col-md-4">
<label class="control-label">Allocation type</label>
@if($economicCode_as !== "")
<input type="text" class="form-control" readonly value="{{ $econ3 }}" >
<input type="hidden" class="form-control" id="allocationtype1" name="allocationtype1" placeholder="" readonly value="{{ $alloc5 }}" >
@else
<select onchange="return getEconomics()" class="form-control" id="allocationtype1" name="allocationtype1" placeholder="" {{ ($economicCode_as == "") ? "" : "readonly" }}>
<option value="">Select Allocation</option>
@foreach($allocationlist as $list)
<option value="{{$list->ID}}" {{($list->ID == $alloc1 || $list->ID == old('allocationtype1')) ? "selected" : ""}}>{{$list->allocation}}</option>
@endforeach
</select>
@endif
</div>
<div class="col-md-4">
<label class="control-label">Economic code</label>
@if($economicCode_as !== "")
<input type="text" class="form-control" readonly value="{{ $econ3 }}" >
<input type="hidden" name="economicCode1" id="economicCode1" class="form-control" readonly value="{{ $economicCode_as }}" >
@else
<select name="economicCode1" id="economicCode1" class="form-control" >
<option >Select Economic Code</option>
@foreach($econocode as $list)
<option value="{{ $list->ID }}" {{ ($list->ID == old('economicCode1') || $list->ID == $economiccode1) ? "selected" : "" }}>({{$list->description }}) {{$list->economicCode}}</option>
@endforeach
</select>
@endif
</div>
</form>
这是路线
Route::get('/voucher/continue', 'CreateContractVoucherController@continu');
Route::post('/voucher/continue', 'CreateContractVoucherController@continu');
和控制器
public function continu(Request $request)
'contractTypeID' => $tblcontracttype,
'contractID' => $tblcontractid,
'companyID' => $tblcompanyid,
'PVNO' => $pvno,
'totalPayment' => $tbltotalpayment,
'paymentDescription' => $narration,
'VAT' => $vatperc,
'VATValue' => $vat,
'WHT' => $whtselect,
'WHTValue' => $wht,
'VATPayeeID' => $tblvatpayeeid,
'WHTPayeeID' => $tblwhtpayeeid,
'amtPayable' => $tblamtPayable,
'preparedBy' => $tblprepareby,
'liabilityBy' => $liabilityby,
'allocationType' => $allocationtype,
'economicCodeID' => $economiccodeid,
'status' => 0,
'datePrepared' => $dateprepared,
'period' => $this->ActivePeriod()
])){
//$data['success'] = "Voucher was edited successfully!";
//$vid = DB::table('tblpaymentTransaction')->where('PVNO', $pvno)->first()->ID;
if(DB::table('tblcontractDetails')->where('ID', $tblcontractid)->first()->paymentStatus == ""){
DB::table('tblcontractDetails')->where('ID', $tblcontractid)->update([
'paymentStatus' => 0
]);
}
if(DB::table('tblcontractDetails')->where('ID', $tblcontractid)->first()->economicVoult == ""){
DB::table('tblcontractDetails')->where('ID', $tblcontractid)->update([
'economicVoult' => $economiccodeid
]);
}
return view('continue', $data);
}
答案 0 :(得分:3)
查看了您的表格并检查了您的投诉后,您显然还没有添加csrf_field
因此在您的表单中添加此行
{{ csrf_field() }}
答案 1 :(得分:0)
您需要保护您的应用程序免受跨站点请求伪造的侵害。
Laravel有一个简单的方法。
如果您使用的是Laravel 5.4,只需在表单中添加{{ csrf_field() }}
。
<form method="POST" action="/profile">
{{ csrf_field() }}
...
</form>
如果您使用Laravel 5.6+,则可以使用@csrf
<form method="POST" action="/profile">
@csrf
...
</form>
Laravel 5.4-https://laravel.com/docs/5.4/csrf
Laravel 5.6-https://laravel.com/docs/5.6/csrf