lubosdz / yii2-captcha-extended

Extended captcha code generator for Yii2 framework with configurable obfuscation level
Other
9 stars 1 forks source link

Unknown property verifyCode in RegistrationForm #1

Closed amlopezalonso closed 1 year ago

amlopezalonso commented 1 year ago

Hi,

Have your extension applied to my login form and have no issues, but when trying it with my registration form I get the following:

yii\base\UnknownPropertyException: Getting unknown property: Da\User\Form\RegistrationForm::verifyCode in /myapp/vendor/yiisoft/yii2/base/Component.php:154 Stack trace:

0 /myapp/vendor/yiisoft/yii2/helpers/BaseHtml.php(2280): yii\base\Component->__get()

1/myapp/vendor/yiisoft/yii2/helpers/BaseHtml.php(1372): yii\helpers\BaseHtml::getAttributeValue()

2 /myapp/vendor/yiisoft/yii2/widgets/InputWidget.php(106): yii\helpers\BaseHtml::activeInput()

3 /myapp/vendor/yiisoft/yii2/captcha/Captcha.php(107): yii\widgets\InputWidget->renderInputHtml()

4 /myapp/vendor/yiisoft/yii2/base/Widget.php(146): yii\captcha\Captcha->run()

5 /myapp/vendor/yiisoft/yii2/widgets/ActiveField.php(795): yii\base\Widget::widget()

6 /myapp/views/user/registration/register.php(61): yii\widgets\ActiveField->widget()

7 //myapp/vendor/yiisoft/yii2/base/View.php(347): require('/usr/local/shar...')

8 /myapp/vendor/yiisoft/yii2/base/View.php(257): yii\base\View->renderPhpFile()

9 /myapp/vendor/yiisoft/yii2/base/View.php(156): yii\base\View->renderFile()

10 /myapp/vendor/yiisoft/yii2/base/Controller.php(407): yii\base\View->render()

11 /myapp/vendor/2amigos/yii2-usuario/src/User/Controller/RegistrationController.php(147): yii\base\Controller->render()

12 [internal function]: Da\User\Controller\RegistrationController->actionRegister()

13 /myapp/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()

14 /myapp/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()

15 /myapp/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()

16 /myapp/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction()

17 /myapp/vendor/yiisoft/yii2/base/Application.php(384): yii\web\Application->handleRequest()

18 /myapp/web/index.php(12): yii\base\Application->run()

19 {main}`

In RegistrationForm I got pretty much the same as in LoginForm:

namespace app\models;

class RegistrationForm extends \Da\User\Form\RegistrationForm
{
    /**
        * @var string
        */
    public $verifyCode;
    /**
        * @inheritdoc
        */
    public function rules()
    {
        $rules   = parent::rules();
        $rules[] = ['verifyCode', 'lubosdz\captchaExtended\CaptchaExtendedValidator',
            'captchaAction' => \yii\helpers\Url::to('/site/captcha'),
                   ];
        return $rules;
    }

    public function attributeLabels()
    {
        $attr = parent::attributeLabels();
        return $attr;
    }
}

And in register.php view:

<?= $form->field($model, 'verifyCode')->widget(yii\captcha\Captcha::class, [
                    'captchaAction' => Url::to('/site/captcha'),
                    'template' => '<div class="text-center">{image}</div><br/> {input} ',
                    'imageOptions' => [
                        'class' => 'img-fluid',
                        'style' => 'cursor:pointer; width: 100%',
                        'title' => Yii::t('app', 'Pulse para refrescar'),
                    ],
                    'options' => [
                        'placeholder' => Yii::t('app', 'Código de verificación'),
                        'class' => 'form-control',
                    ],
                    ])->label(false)
                ?>

What can I be doing wrong?

amlopezalonso commented 1 year ago

Ah sorry, needed to map RegistrationForm in web.php:

'classMap' => [
                'LoginForm' => 'app\models\LoginForm',
                'RegistrationForm' => 'app\models\RegistrationForm',
              ],