Answer the question
In order to leave comments, you need to log in
How to prohibit adding GET parameters to existing ones?
I pass parameters using the GET method. The URL looks like this ?SearchForm%5Bage%5D=1 Resubmitting
the data in the URL does not change what is already there, but adds another bunch of data
?SearchForm%5Bage%5D=1&SearchForm%5Bage%5D=1
How to tell Yii2, so that it doesn't pile up the URL with data?
Model
class SearchForm extends Model
{
public $age;
}
$model = new SearchCleanerForm();
$model->load(Yii::$app->request->get());
return $this->render('list', ['model' => $model]);
<?php
$form = ActiveForm::begin([
'id' => 'search-cleaners',
'method' => 'get',
'options' =>['class' => 'form-vertical'],
]);
?>
<?= $form->field($model, 'smoking') ?>
<?php ActiveForm::end(); ?>
Answer the question
In order to leave comments, you need to log in
Only manual input of the form helped.
<form action="<?= Url::toRoute(['/cleaner/list']) ?>" method="get" class="form-vertical" id="search-cleaners">
<?= Html::activeTextInput($model, 'age') ?>
</form>
You need to add an action parameter equal to your route without parameters in the ActiveForm
widget . For example,
$form = ActiveForm::begin([
'id' => 'search-cleaners',
'method' => 'get',
'action' => ['/cleaner/list'],
'options' =>['class' => 'form-vertical'],
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question