gpt4 book ai didi

captcha - Yii2 模块中的验证码操作 ID 无效

转载 作者:行者123 更新时间:2023-12-04 10:37:16 25 4
gpt4 key购买 nike

我在我的自定义联系人模块中收到了无效的验证码操作 ID 异常。我设法显示了验证码,但模型验证规则抛出了无效的操作 ID 异常。下面是我的代码:

联系我们/ Controller /DefaultController.php

class DefaultController extends Controller
{
public function behaviors()
{
return [
'access' => [
'class' => \yii\filters\AccessControl::className(),
'rules' => [
[
'actions' => ['captcha','index'],
'allow' => true,
],
]
]
];
}

public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}

public function actionIndex()
{
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->contact(setting::ADMIN_EMAIL_ADDRESS)) {
Yii::$app->session->setFlash('contactFormSubmitted');

return $this->refresh();
} else {
return $this->render('index', [
'model' => $model,
]);
}
}
}

联系我们/models/ContactForm.php
public function rules()
{
return [
// name, email, subject and body are required
[['name', 'email', 'subject', 'body','verifyCode'], 'required'],
// email has to be a valid email address
['email', 'email'],
// verifyCode needs to be entered correctly
['verifyCode', 'captcha','captchaAction'=>'default/captcha'],
];
}

联系我们/views/default/index.php
 <?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'subject') ?>
<?= $form->field($model, 'body')->textArea(['rows' => 6]) ?>
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
'captchaAction' => 'default/captcha',
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
]) ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
</div>
<?php ActiveForm::end(); ?>

我收到以下错误:
Exception (Invalid Configuration) 'yii\base\InvalidConfigException' with message 'Invalid CAPTCHA action ID: default/captcha'in E:\wamp\www\yii-application\vendor\yiisoft\yii2\captcha\CaptchaValidator.php:81

我错过了什么吗?

最佳答案

您应该修改您的验证规则:

['verifyCode', 'captcha','captchaAction'=>'/contactus/default/captcha'],

关于captcha - Yii2 模块中的验证码操作 ID 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28497432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com