以{{FORM ::}}的形式从视图发送值并在控制器

时间:2016-11-29 16:30:21

标签: laravel-4.2

我想从视图中向控制器发送值,它即将到来" null",我期待输入搜索按钮,

观看页面代码:

 {{ Form::open(['method'=>'POST','action'=>'searchingDoctors','class'=>'navbar-form navbar-left','role'=>'search'])  }}

            <div class="input-group custom-search-form">
                <input type="text" class="form-control" name="search" placeholder="Search...">
            </div>
                <input type="submit" id="search" name="search" value="Serach" class="search" />
            {{ Form::close() }}

route.php代码:

Route::post('searchingDoctors/{search}', array('as'=>'searchingDoctors','uses'=>'PublicSearchController@searchingDoctors'));

控制器文件代码:

public function searchingDoctors($search) {

        dd($data = Input::get($search));
}

2 个答案:

答案 0 :(得分:1)

您需要在控制器中执行以下操作

public function searchingDoctors() {

        $data = Input::get("search");
}

更改路线
Route::post('searchingDoctors/{search}', array('as'=>'searchingDoctors','uses'=>'PublicSearchController@searchingDoctors'));

Route::post('searchingDoctors, array('as'=>'searchingDoctors','uses'=>'PublicSearchController@searchingDoctors'));

修改

同时将视图更改为以下

{{ Form::open(['method'=>'POST','action'=>'searchingDoctors','class'=>'navbar-form navbar-left','role'=>'search'])  }}

            <div class="input-group custom-search-form">
                <input type="text" class="form-control" name="search" placeholder="Search...">
            </div>
                <input type="submit" id="search" name="search-button" value="Serach" class="search" />
            {{ Form::close() }}

答案 1 :(得分:0)

试试这个:

public function searchingDoctors() {

        dd($data = Input::get('search'));
}

并确保您已导入

use Illuminate\Support\Facades\Input;