T
T
tincap2015-09-02 11:58:18
Yii
tincap, 2015-09-02 11:58:18

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;
}

Controller
$model = new SearchCleanerForm();
$model->load(Yii::$app->request->get());
return $this->render('list', ['model' => $model]);

Performance
<?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

2 answer(s)
T
tincap, 2015-09-02
@tincap

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>

A
Anton, 2015-09-02
@karminski

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 question

Ask a Question

731 491 924 answers to any question