提交表单,向URL添加输入

时间:2015-07-20 19:27:41

标签: laravel laravel-4 laravel-5

我有一个单一输入的常规表单:

{{ Form::open(array('id' => 'form_search')) }}
    <div class="form-group">
        {{ Form::text('search', '', array('class' => 'form-control', 'placeholder' => 'Search...')) }}
    </div>
{{ Form::close() }}

提交表单后,我希望它通过以下网址重定向到显示结果的页面:

http://www.website.com/search/<QUERY_HERE>

例如,如果有人在表单输入中键入john并提交了表单,则重定向到的URL将如下所示:

http://www.website.com/search/john

我该怎么做?

1 个答案:

答案 0 :(得分:1)

在你的routes.php中

catch (SqlException erro)
{
    throw erro;
}

然后将路线添加到表单:

//Handle form submit
Route::get('search', 'YourSearchController@yourSearchFunction');
//Return results
Route::get('search/{search}', 'YourSearchController@yourSearchResults');

然后在yourSearchController中:

{{Form::open(['route' => 'search'])}}

然后也在yourSearchController中:

function yourSearchFunction() {
    $search = Input::only(['search']);
    return Redirect::to('search/'.$search);
}