Data from form to a controller without model

Hi guys I have problem with passing data from forms to a controller without model… Or with model, but just DynamicModel

This is from controller where I’m using dynamicmodel




public function actionGenerate()

    {

        $dmodel = new DynamicModel([

            'dcount', 'dtime', 'dcaption'

        ]);


        if ($dmodel->load(Yii::$app->request->post()))

        {

            var_dump(Yii::$app->request->post());

            die();

            return $this->render(['index']);

        }

        else

        {

            return $this->renderAjax('show_feeds', [

                'dmodel' => $dmodel,

            ]);

        }

    }



I put there vur_damp but I never gonna get there and I don’t understand why

this is my _form.php




 <?php $form = ActiveForm::begin([

            'method' => 'post',

        ]); ?>


        <?= $form->field($dmodel, 'dcount',['options' => ['class' => 'col-md-2']])->textInput()->label('3 or 1'); ?>


        <?= $form->field($dmodel, 'dtime',['options' => ['class' => 'col-md-2']])->textInput()->label('Repeate in sec'); ?>


        <?= $form->field($dmodel, 'dcaption',['options' => ['class' => 'col-md-2']])->textInput()->label('Name of link');?>

    </div>

    <div class="form-group">

        <?= Html::button('Generate', [

                'value'=>Url::to(['generate']),

                'class'=>'btn btn-primary grid-button modalButton'

        ]); ?>

        <?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>


        <?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>

    </div>

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



Have you checked var_dump($_POST)? Have you checked what fields are passed from POST (in browser console) ?

I solved my problem thisway

_form.php




<div class="xml-feed-form">

    <div class="row">

        <?php $form = ActiveForm::begin([

            'method' => 'post',

        ]); ?>


        <?= $form->field($model, 'count',['options' => ['class' => 'col-md-2']])->textInput()->label('3 or 1'); ?>


        <?= $form->field($model, 'time',['options' => ['class' => 'col-md-2']])->textInput()->label('Repeate in sec'); ?>


        <?= $form->field($model, 'caption',['options' => ['class' => 'col-md-2']])->textInput()->label('Caption of link'); ?>


    <div class="form-group">

        <?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>

    </div>

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

    </div>

</div>



and action in controller




$model = new Feed();


        if (Yii::$app->request->post())

        {

            foreach (Yii::$app->request->post('Feed') as $item)

            {

                (!isset($model->count)) ? $model->count =  $item :

                    (!isset($model->time) ? $model->time = $item :

                        $model->caption = $item);

            }

            return $this->render('show_feeds', [

                'model' => $model,

            ]);

        }

        else

        {

            return $this->renderAjax('_form', [

                'model' => $model,

            ]);

        }



I have a little problem with selecting data from post, so I used foreach like you can see above

because simply model->load(post) doesn’t work in this solution




array(2) { ["_csrf"]=> string(56) "eWRfYi5BZE4MFxNQXQUwOhIhEE9iA1w8Pg0RNxwHBiwTVz4LXgQMeg==" ["Feed"]=> array(3) { ["count"]=> string(1) "1" ["time"]=> string(1) "2" ["caption"]=> string(1) "3" } }



What it means that _csrf and how can I filter it ?

Thanks :)