Failed to validate invalid send data request (# 400) in yii2 (if video format selected)

I am new yii2 so I have this problem. I want to use fileinput so i add fileinput this url http://www.yiiframework.com/doc-2.0/guide-input-file-upload.html if i create a new model with file input (select video) and if i I will delete an element in the model, like this: ** Request Ber (no. 400) Failed to verify the sending of data. if i select an image it works ok how to load video in yii2?

my log:

exception 'yii\web\BadRequestHttpException' with message 'Unable to verify your data submission.' in C:\xampp\htdocs\project\vendor\yiisoft\yii2\web\Controller.php:110
Stack trace:
C:\xampp\htdocs\project\vendor\yiisoft\yii2\base\Controller.php(149): yii\web\Controller->beforeAction(Object(yii\base\InlineAction))
C:\xampp\htdocs\project\vendor\yiisoft\yii2\base\Module.php(455): yii\base\Controller->runAction('delete', Array)
C:\xampp\htdocs\project\vendor\yiisoft\yii2\web\Application.php(84): yii\base\Module->runAction('music/delete', Array)
C:\xampp\htdocs\project\vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
C:\xampp\htdocs\project\web\index.php(12): yii\base\Application->run()
{main}

      

Please help me? Thank!

+3


source to share


2 answers


Code from YII2 core.

if ($this->enableCsrfValidation && Yii::$app->getErrorHandler()->exception === null && !Yii::$app->getRequest()->validateCsrfToken()) {
    throw new BadRequestHttpException(Yii::t('yii', 'Unable to verify your data submission.'));
}

      



Try disabling csrf checking.

MyController extends Controller {
    public $enableCsrfValidation = false;
}

      

+8


source


See update instructions:

[ https://github.com/yiisoft/yii2/blob/master/framework/UPGRADE.md#upgrade-from-yii-20-beta [[1 ])



Update your main layout file by adding this line to the: section <?= Html::csrfMetaTags() ?>

. This change is necessary because yii \ web \ View no longer automatically generates CSRF meta tags due to issue # 3358

0


source







All Articles