PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 28, 2022

[FIXED] Post inside controller not loading into model in Yii2

 February 28, 2022     yii, yii-extensions, yii-form, yii2, yii2-advanced-app     No comments   

Issue

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



Answered By - adnen manssouri
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing