如何解决错误的请求(#400)无法验证您在yii2中提交的数据? [英] How to solve Bad Request (#400) Unable to verify your data submission in yii2?

查看:305
本文介绍了如何解决错误的请求(#400)无法验证您在yii2中提交的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在提交表单时出现此错误:

I have got this error, when submit the form:


Bad Request (#400) Unable to verify your data submission.


我有<?= Html :: csrfMetaTags()?> 。我认为,我有这个问题,因为我使用了datepicker。使用ActiveForm创建表单。

I have got <?= Html::csrfMetaTags() ?> in the layout. I think, that this problems I have, because I use datepicker. Form create with ActiveForm.

我必须做什么?这里是表格的代码:

What I must to do? Here is code of the form:

<?
        $form2 = ActiveForm::begin(['id' => 'user-univer']);
        echo $form2->field($model2, 'university')->label('Input university name:');
        echo $form2->field($model2, 'degree')->label('Input your education specialization:');
        //echo $form2->field($model2, 'date')->label('Input your education date:');
        echo '<label class="control-label">Education time:</label><br/>';
        echo '<span>Start date of your education:</span>';
        echo DatePicker::widget([
            'name'  => 'date_from',
            'value'  => $value,
            'dateFormat' => 'dd.MM.yyyy',
        ]);
        echo '<span>End date of your education:</span>';
        echo DatePicker::widget([
            'name'  => 'date_to',
            'value'  => $value,
            'dateFormat' => 'dd.MM.yyyy',    
        ]);
        echo '<br/><br/>';


        echo $form2->field($model2, 'info')->textarea()->label('Any other information about your university degree:');
        echo Html::submitButton('Add university', ['class' => 'btn btn-primary btn-univer']);
        ActiveForm::end(['id' => 'user-univer']);

        } ?>

UPD:没有datepicker我有同样的问题,为什么?如何解决它?

UPD: without datepicker I have got the same problems, why? how to solve it?

推荐答案

在您的表单中添加csrf标记字段

Add csrf token field in your form

<input type="hidden" name="<?=Yii::$app->request->csrfParam?>" value="<?=Yii::$app->request->getCsrfToken()?>" />

将解决您的问题。

这篇关于如何解决错误的请求(#400)无法验证您在yii2中提交的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆