There are 2 actions in one controller. The first form is the choice of checkboxes. The second form is the output of these checkboxes. How to transfer the values ​​from one form to another in order to turn them over there - a person has noted or not.

The problem is that the data is not stored in the database. In the model, created custom public variables and added to the rules. In the first form, I collect ActiveForm data, that is, I can transfer it to the controller method. Now how can I transfer all my fields to another action ??

The first form and method

public function actionExport($id) { return $this->renderAjax('/objects/export', ['model' => $this->findModel($id)]); } 

and method

  <?php $form = \yii\widgets\ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data'], 'enableClientValidation' => false, 'enableAjaxValidation' => true, ]) ?> <p><label><input type="checkbox" id="export"/> Все уведомления</label></p> <div id="checkbox_export"> <?= $form->field($model, 'export_realtor')->checkbox() ?> <?= $form->field($model, 'export_address')->checkbox() ?> <?= $form->field($model, 'export_attributes')->checkbox() ?> <?= $form->field($model, 'export_square')->checkbox() ?> <?= $form->field($model, 'export_levels')->checkbox() ?> <?= $form->field($model, 'export_price')->checkbox() ?> <?= $form->field($model, 'export_info')->checkbox() ?> </div> <?php \yii\widgets\ActiveForm::end(); ?> <?= \yii\helpers\Html::a('PDF', ['pdf', 'id' => $model->id], ['class' => 'btn btn-primary btn-sm', 'target' => '_blank']) ?> <?= \yii\helpers\Html::a('Напечатать', ['pdf', 'id' => $model->id], ['class' => 'btn btn-primary btn-sm', 'target' => '_blank']) ?> <?php $script = <<< JS $("#export").change(function () { $("#checkbox_export input:checkbox").prop('checked', $(this).prop("checked")); }); JS; $this->registerJs($script); ?> 

And the second form renders a pdf file

  public function actionPdf($id) { $pdf = new Pdf([ 'mode' => Pdf::MODE_UTF8, 'content' => $this->renderPartial('/objects/pdf', ['id' => $id, 'model' => $model = $this->findModel($id)]), 'options' => [ 'title' => 'Text', 'subject' => 'Text' ], 'methods' => [ 'SetHeader' => ['Generated By: Krajee Pdf Component||Generated On: ' . date("r")], 'SetFooter' => ['|Page {PAGENO}|'], ] ]); return $pdf->render(); } 

Data on this pdf in the view / objects / pdf '. Here you now need to check whether the checkbox is checked - <

 ?php if($model->export_realtor): ?> .... <?php endif; ?> 
  • You cannot transfer data from an action to an action, but there is an intermediary-view (view) between them, here you pass it through. Ie action1 calls the input form, from the input form you call action2 and transfer data there, and then action2 outputs this data on the output form - perfect
  • I have it - on the form1 button <?= \yii\helpers\Html::a('PDF', ['pdf', 'id' => $model->id], ['class' => 'btn btn-primary btn-sm', 'target' => '_blank']) ?> We contact action1, and action1 is already rendering a form2. But how exactly to transfer this data to action ?? - Vlad Shkuta
  • The data in http can only be transferred with a get and post request - perfect

0