yiiyii2yii2-advanced-appyii-extensionsyii-form

Post inside controller not loading into model in Yii2


When I want to get the variable from the form the post action doesn't load .

This is my view:

<?php
        $form = ActiveForm::begin();
        ?>
            <div class="form-group">
                <input type="text" name="username" placeholder="FullName">

                <?= Html::a(Yii::t('app', 'Start'), ['start', 'link' => $model->link], ['type' => 'button','class' => 'btn btn-primary btn-round']) ?>
            </div>

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

This is my controller:

if ($model->load(Yii::$app->request->post())){
    exit(var_dump('everything is ok'));
}else {
    exit(var_dump('nothing is right'));

}

The result is 'nothing is right'.


Solution

  • Finally I find the solution

    <?php
    $form = ActiveForm::begin(
        [
            'action' => 'start',
        ]
    );
    ?>
    <div class="form-group">
        <input type="text" name="username" placeholder="FullName">
        <?= Html::a('submit', Url::to(['start', 'link' => $model->link]), ['data-method' => 'POST']) ?>
    </div>
    
    <?php ActiveForm::end();?>
    

    thank you for all