0

I am using the ActiveForm widget to send a model from the view to the controller. It works great but now I also need to send a checkbox that is not part of any model. This is my checkbox:

<?= Html::checkbox('swim', false, ['id' => 'idSwim']) ?>

If my checkbox is part of a model, I could send it in this way:

<?= $form->field($myCheckboxModel, 'swim')->checkbox(['id' => 'idSwim') ?>

But it doesn't belong to any model, so I don't know how to send it. I even send different models in the same forms.

1
  • 1
    Your first line of code should work. It won't load the field into your model though, but you should be able to retrieve it from the POST array Commented Sep 18, 2017 at 19:35

1 Answer 1

1

Retrieve the posted value in your controller like this:

$swim = Yii::$app->request->post('swim')

If the field is related to one of your models, you could also consider defining it as a property: http://www.yiiframework.com/doc-2.0/guide-concept-properties.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.