S
S
Svetlana Galenko2018-11-18 15:15:14
Yii
Svetlana Galenko, 2018-11-18 15:15:14

I gave up... Getting unknown property: app\models\forms\SignupForm::name?

Hello, I've been struggling with one error all day...
5bf15637e9cd8855698451.png
It seems to me that the problem is in the controller, but I don't understand what exactly the problem is, please help..
I use two models in one action.. is this correct?
Or maybe it's a completely different error?
SiteController.php:

public function actionIndex()
    {
        /* Создаем экземпляр класса */
        $model = new ContactForm();
        $model->put_date = date('y-m-d');
        $model->hide = 'show';
        /* получаем данные из формы и запускаем функцию отправки contact, если все хорошо, выводим сообщение об удачной отправке сообщения на почту */
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            Yii::$app->session->setFlash('success', 'Спасибо за обращение к нам. Мы постараемся ответить вам как можно скорее');
            return $this->refresh();
            /* иначе выводим форму обратной связи */
        }
        

        if (!\Yii::$app->user->isGuest)
            return $this->redirect(['/user/profile/index']);

        $model = new SignupForm();
        if ($model->load(\Yii::$app->request->post())) {
            if ($model->signup() === true) {
                return $this->render('success', [
                    'model' => $model,
                ]);
            }
        }
        return $this->render('index', [
            'model' => $model,
        ]);


    }

And naturally in one view I use two forms, one for contacts and the second for registration..
<?php $form = ActiveForm::begin([
                            'method' => 'POST',
                            'options' => [
                                    'class' => 'form-inline',
                            ]

                    ]); ?>

                        <?= $form->field($model, 'username', ['inputOptions' => ['class' => 'form-control email']])->label(false) . $model->getAttributeLabel('Ваше Имя') ?>

                        <?= $form->field($model, 'email', ['inputOptions' => ['class' => 'form-control email']])->label(false) . $model->getAttributeLabel('Ваш E-mail') ?>

                    <?= $form->field($model, 'verifyCode')->widget(Captcha::className()) ?>

                    <?php if ($model->hasReferer() != null) { ?>
                    Вас пригласил <?= $model->getReferer()->getUsername() ?>
                    <?php } ?>

                        <input type="submit" class="submit" value="Регистрация">

                        <?php ActiveForm::end(); ?>

<div class="contact_from">
                    <?php if (Yii::$app->session->hasFlash('success')): ?>

                        <p class="success" id="success" style="display:none;"></p>
                        Спасибо за обращение к нам. Мы постараемся ответить вам как можно скорее
                        </p>
                    <?php else: ?>

                    <?php $form = ActiveForm::begin(['id' => 'contact_form']); ?>
                    <!-- Message Input Area Start -->
                    <div class="contact_input_area">
                        <div class="row">

                            <div class="col-md-12">
                                <div class="form-group">
                                    <?= $form->field($model, 'name', ['inputOptions' => ['class' => 'form-control', 'id' => 'name']])->textInput(['placeholder' => "Ваше имя"])->label(false); ?>
                                </div>
                            </div>
                                    <?= $form->field($model, 'email', ['inputOptions' => ['class' => 'form-control', 'id' => 'email']])->textInput(['placeholder' => "Ваш E-mail"])->label(false); ?>
                            <div class="col-md-12">
                                <div class="form-group">
                                    <?= $form->field($model, 'subject', ['inputOptions' => ['class' => 'form-control', 'id' => 'subject']])->textInput(['placeholder' => "Тема сообщения"])->label(false); ?>
                                </div>
                            </div>
                            <div class="col-12">
                                <div class="form-group">
                                    <?= $form->field($model, 'body', ['inputOptions' => ['class' => 'required valid', 'id' => 'message']])->textarea(['cols' => 30,'rows' => 4])->label(false); ?>
                                </div>
                            </div>
                            <div class="col-12">
                                <div class="form-group">
                                    <?= $form->field($model, 'verifyCode')->widget(Captcha::className()) ?>
                                </div>
                            </div>
                            <div class="col-12">
                            <?= Html::submitButton(\Yii::t('app', 'Отправить'), ['class' => 'btn submit-btn']) ?>
                            </div>
                        </div>
                    </div>

                        <?php ActiveForm::end(); ?>

                    <?php endif; ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-11-18
@swallow_97

The problem is that somewhere your code is accessing the name property of the app\models\forms\SignupForm object, but it's not there. If you look at the entire stack, and not its last entry, you will see exactly where you are accessing it.
I have an idea what it is
This happens apparently due to the fact that in the action when rendering

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

You don't have ContactForm in $model as you expect, but SignupForm. Since
But is not a fact, there is exact data in the error. Give the full call stack from the error if you can't find it yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question