【发布时间】:2018-01-02 08:13:22
【问题描述】:
我想创建搜索表单,然后按视图显示结果。在我提交结果显示在视图搜索组中但提交后刷新页面时我得到重新提交我如何通过发布路由搜索并防止通过刷新页面重新提交?
public function src_fn(){
$para=Input::get('txt_pro_id');
$result=DB::table('testing_tbl')->where('pro_id','=',$para)->paginate(5);
return View::make('searchome')->with('result',$result);
}
我的搜索视图
<form method="post" action="{{route('findsresult')}}" name="frm_srch" role="search">
{!! csrf_field() !!}
<input type="Text" name="txt_pro_id" id="txt_pro_id">
<input type="Submit" value="OK">
</form>
我的搜索视图
<table cellpadding="10px" width="100%" class="table_str">
<thead style="font-size: 11px;">
<tr>
<th>Pro ID</th>
<th>Pro Name</th>
<th>Pro price</th>
</tr>
</thead>
<tbody style="font-size: 11.5px;">
@foreach($result as $vals)
<tr scope="row" style="border-bottom: solid 1px #ccc">
<td>{{$vals->pro_id}}</td>
<td>{{$vals->pro_name}}</td>
<td>{{$vals->pro_price}}</td>
</tr>
@endforeach
</tbody>
</table>
<?php echo $result->render(); ?>
我的路线
Route::post('findsresult', 'SearchController@src_fn')->name('findsresult');
【问题讨论】:
-
浏览器默认!如果你不希望浏览器显示
confirm form resubmission,最好使用 get -
@arunkumar 是的,我明白了,但是当我使用时,我的网址变得如此混乱
-
这可能对您的问题有帮助:stackoverflow.com/questions/6320113/…
-
恕我直言,使用
GET进行搜索和过滤是最好的解决方案。如果您的搜索功能是针对公共用户的,它将由search engine索引。如果您使用POST,这是不可能的。 -
您可以添加一个 get 路由来显示结果,然后在
src_fn方法中重定向到该路由以破坏发布请求!
标签: php laravel laravel-5 laravel-5.3