Search code examples
phpyii2active-form

Yii2. ActiveFrom. Add GET-param to URL without model array


I want simply to add GET-param to URL from user. I use third party module action, so I don't want to change the signature that is

public function actionReset($id, $code)

I have such model in controller

$model = new DynamicModel([
    'code'
]);
$model->addRule(['code'], 'required');
$model->addRule(['code'], 'string');

And such ActiveForm

<?php $form = ActiveForm::begin([
    'method' => 'get',
    'action' => [
        \yii\helpers\Url::current()
    ]
]) ?>

<?php echo $form->field($model, 'code')->textInput()->label(false); ?>

<?php echo Html::submitButton(Yii::t('user', 'Continue')); ?>

<?php ActiveForm::end(); ?>

And with such implementation it passes with an array wrapper:

enter image description here

Is it possible to avoid such wrapper without custom js?


Solution

  • I found an answer here

    Now my view code looks like

                <?=Html::beginForm(Url::current(), 'get', ['csrf' => false]);?>
                <?=Html::input('text', 'code', 'test')?>
    
                <?=Html::a('Submit', '', [
                    'data' => [
                        'method' => 'get',
                    ]
                ])?>
                <?=Html::endForm();?>