Php Yii2高级,无法验证您的数据提交错误
我正在使用yii2高级模板建立一个网站。 当我想使用表单创建新行时,它可以工作,但是在几秒钟后的第二次提交或更新中,我遇到了这个错误。 我在这里读了很多答案,但我不想禁用crf token和aleardyPhp Yii2高级,无法验证您的数据提交错误,php,yii2,yii2-advanced-app,Php,Yii2,Yii2 Advanced App,我正在使用yii2高级模板建立一个网站。 当我想使用表单创建新行时,它可以工作,但是在几秒钟后的第二次提交或更新中,我遇到了这个错误。 我在这里读了很多答案,但我不想禁用crf token和aleardy <?= Html::csrfMetaTags() ?> 布局: <?php $this->beginPage() ?> <!DOCTYPE html> <html lang="<?= Yii::$app->langu
<?= Html::csrfMetaTags() ?>
布局:
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex, nofollow">
<?= Html::csrfMetaTags() ?>
<title>WritesDown » <?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body
class="<?= isset(Yii::$app->params['bodyClass']) ? Yii::$app->params['bodyClass'] : "skin-blue sidebar-mini"; ?>">
<?php $this->beginBody() ?>
<?= $content; ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
一种解决方案可能是这样的,但仅在特殊情况下推荐强>
对一个控制器的所有操作禁用csrf检查
Add the follow code to controller part:
public $enableCsrfValidation = false;
使用以下命令:
行动前的公共职能($行动)
{
$this->enableCsrfValidation=false;
返回父项::操作前($action);
}
在您的表单中添加这一行:据我所知,您的两个表单逐个提交,在这种情况下,您的csrf令牌将更改,因为当您的form1提交时,csrf令牌将更改。您能告诉我们更多的细节吗?这样我们就可以提供您想要的。@Peerbits BackendTeam我正在自动使用activeform此字段added@nageennayak不,两次之后,假设您使用表单添加了一行,并在几秒钟后将页面保留在此表单上更新或重新提交此错误出现。当我想登录到我的后端时,也会出现一些情况。您是使用带有提交按钮的普通表单提交,还是使用ajax调用。
Add the follow code to controller part:
public $enableCsrfValidation = false;