When I use ActiveForm widget with method=get, parameters from $_GET appears inside form tag as hidden inputs. Is it a bug? How to get rid of these inputs?
Search model:
class OrderSearch extends Order
{
public function formName()
{
return '';
}
public function rules()
{
return [
[['id'], 'integer'],
];
}
public function search($params)
{
$query = Order::find();
if (!($this->load($params) && $this->validate())) {
return $query;
}
$query->andFilterWhere(['id' => $this->id]);
return $query;
}
}
Controller action:
public function actionIndex()
{
$searchModel = new OrderSearch();
$dataProvider = new ActiveDataProvider([
'query' => $searchModel->search($_GET),
]);
return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]);
}
View:
<?php $form = ActiveForm::begin([
'id' => 'order-search-form',
'method' => 'get',
]) ?>
<?= $form->field($searchModel, 'id') ?>
<?= Html::submitButton('Find', ['class' => 'btn btn-primary']) ?>
<?php ActiveForm::end() ?>
Resulting form HTML:
<form id="order-search-form" action="/order/index" method="get">
<input type="hidden" name="id" value="111">
<div class="form-group field-id">
<label class="control-label" for="id">Number</label>
<input type="text" id="id" class="form-control" name="id" value="111">
<div class="help-block"></div>
</div>
<button type="submit" class="btn btn-primary">Find</button>
</form>