我目前在使用POST
将数据从搜索表单发布到另一页时遇到问题。我在名为index的页面中有一个搜索表单。
在此索引页面上,我正在张贴另一种形式的表格,称为动物搜索。当我尝试使用_post
数据进行搜索并且一个字段为空时,会引发错误。
索引
<div class="modal-dialog" role="document">
<div class="modal-content">
<form class="form-horizontal" method="POST" action="/import-conditions/animal/animal-search">
<div class="modal-header">
<h4 align ="center"class="modal-title" >Animal and Animal Products Criteria Search</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="common" class="col-sm-2 control-label">Common Name</label>
<div class="col-sm-10">
<input type="text" name="common" class="form-control" id="common" placeholder="Common Name" >
</div>
</div>
<div class="form-group">
<label for="scientifc" class="col-sm-2 control-label">Scientifc Name</label>
<div class="col-sm-10">
<select name="lp" class="form-control" id="lp">
<option value="">Choose</option>
<!-- -->
</select>
</div>
</div>
<div class="form-group">
<label for="category" class="col-sm-2 control-label">Category</label>
<div class="col-sm-10">
<select name="category" class="form-control" id="category">
<option value="">Choose</option>
</select>
</div>
</div>
<div class="form-group">
<label for="variety" class="col-sm-2 control-label">Variety</label>
<div class="col-sm-10">
<input type="text" name="variety" class="form-control" id="variety" placeholder="Variety" >
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Search</button>
</div>
</form>
</div>
</div>
动物搜索
try
{
$searchModel = new AnimalSearch();
$searchModel->common = $_POST['common'];
$searchModel->scientific = $_POST['scientific'];
$searchModel->origin = $_POST['origin'];
$searchModel->variety = $_POST['variety'];
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('animalsearch', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
catch(\Exception $ex )
{
var_dump($ex->getMessage()); die();
}