PHP   发布时间:2022-04-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php – Yii2 – 错误请求(#400)无法验证您的数据提交大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的yii2应用程序工作正常,直到昨天,但今天提交表单显示错误. “错误请求(#400)无法验证您的数据提交.”

我在stackoverflow上发现了很多这样的问题,人们建议禁用csrf验证我也尝试禁用csrf验证.我甚至更新了我的作曲家仍然无法正常工作.

请提出任何其他可能的解决方

这是我的表格代码: –

<h2>Open an Account</h2>
                  <?PHP
                    $form = ActiveForm::begin([
                            'id' => 'live-account-form','enableClientValidation' => true,'fieldConfig' => [
                                'template' => '{input}{error}','options' => [
                                    'tag' => false,]
                            ],'options' => [
                                'class' => 'form-horizontal'
                            ]
                        ]);
                  ?>

                  <div class="form-group">
                    <label for="signupform-first_name" class="col-sm-3 control-label">First Name*</label>
                    <div class="col-sm-9 field-signupform-first_name">
                        <?= $form->field($model,'first_name')->textInput(['placeholder' => "Enter First Name"]) ?>  

                    </div>
                  </div> 

                  <div class="form-group">
                    <label for="singupform-last_name" class="col-sm-3 control-label">Last Name*</label>
                    <div class="col-sm-9 field-signupform-last_name">
                        <?= $form->field($model,'last_name')->textInput(['placeholder' => 'Enter Last Name']) ?> 
                    </div>
                  </div>   

                  <div class="form-group">
                    <label for="signupform-email" class="col-sm-3 control-label">Email*</label>
                    <div class="col-sm-9 field-signupform-email">
                        <?= $form->field($model,'email')->textInput(['placeholder' => "Enter Email Address"]) ?>
                    </div>
                  </div>

                  <div class="form-group">
                    <label for="signupform-country" class="col-sm-3 control-label">Country*</label>
                    <div class="col-sm-9 field-signupform-country">
                        <?= $form->field($model,'country')->dropDownList(
                            ArrayHelper::map(PhCountry::find()->all(),'intid','country_name'),[
                                'prompt' => 'Select Country','onchange' => '$( "select#signupform-country_code" ).html("showLoading");
                                    $.get( "index.PHP/site/fetch-country-code?id='.'"+$(this).val(),function(data) {
                                        $( "#signupform-country_code" ).val(data);
                                    });'
                            ]
                        ) ?>
                    </div>
                  </div>

                  <div class="form-group">
                      <label class="col-sm-3 control-label">Phone Number*</label>
                      <div class="col-sm-9 phone-number-div">
                        <div>
                        <?= $form->field($model,'country_code')->textInput(['placeholder' => 'Code','class' => 'country-code form-control']) ?>
                        </div>
                        <div class="field-signupform-phone">
                        <?= $form->field($model,'phone')->textInput(['placeholder' => 'Enter Phone Number','class' => 'enter-phone-number form-control']) ?>
                        </div>
                      </div>
                    </div>

                    <button type="submit" class="btn btn-default">Create Account</button>
                  <?PHP
                    ActiveForm::end();
                  ?>

这是我在控制器内的动作代码: –

public function actionIndex()
{
    Yii::$app->controller->enableCsrfValidation = false;
    $model = new SignupForm();
    if ($model->load(Yii::$app->request->post())) {
        //print_r($model);
        if ($user = $model->signup()) {
            if($model->sendRegistrationEmail($user)) {
                Yii::$app->session->setFlash('emailSent','An email containing confirmation link is sent to your email Address.');
                if (Yii::$app->getUser()->login($user)) {
                    return $this->goHome();
                }    
            } 
        }
        //exit;
    }

    return $this->render('index',[
        'model' => $model,]);
}
用这个 :
public function beforeAction($action) 
{ 
    $this->enableCsrfValidation = false; 
    return parent::beforeAction($action); 
}

Do not disable CSRF

大佬总结

以上是大佬教程为你收集整理的php – Yii2 – 错误请求(#400)无法验证您的数据提交全部内容,希望文章能够帮你解决php – Yii2 – 错误请求(#400)无法验证您的数据提交所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: