S
S
Svetlana Galenko2018-10-26 18:08:23
Yii
Svetlana Galenko, 2018-10-26 18:08:23

After creating a feedback form on the site, the following error occurs: Call to a member function isAttributeRequired() on null?

I am using yii2. After creating the return form on the site, an error occurs:

Call to a member function isAttributeRequired() on null
1. in C:\Users\acer\OSPanel\domains\medicalyii2\vendor\yiisoft\yii2\widgets\ActiveField.php at line 915                     
/**
 * Adds aria attributes to the input options.
 * @param $options array input options
 * @since 2.0.11
 */
protected function addAriaAttributes(&$options)
{
    if ($this->addAriaAttributes) {
        if (!isset($options['aria-required']) && $this->model->isAttributeRequired($this->attribute)) {
            $options['aria-required'] = 'true';
        }
        if (!isset($options['aria-invalid'])) {
            if ($this->model->hasErrors($this->attribute)) {
                $options['aria-invalid'] = 'true';
            }
        }
    }
}

2. yii\base\ErrorHandler::handleFatalError()

I clarify that I am using two forms from the same model.. The first form works, but there was a problem with the second one.. Please help me fix it...
Here is my form:
<?php if (Yii::$app->session->hasFlash('contactFormSubmitted')): ?>

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

                <?php else: ?>

                    <?php $form = ActiveForm::begin(['id' => 'contact_form']); ?>

                    <div class="col-md-4"><?= $form->field($model, 'name', ['inputOptions' => ['class' => 'input', 'id' => 'contact_name']])->textInput(['placeholder' => "Your full name"])->label(false); ?></div>

                    <div class="col-md-4"><?= $form->field($model, 'email', ['inputOptions' => ['class' => 'input', 'id' => 'contact_email']])->textInput(['placeholder' => "E-mail Address"])->label(false); ?></div>

                    <div class="col-md-4"><?= $form->field($model, 'subject', ['inputOptions' => ['class' => 'input', 'id' => 'contact_subject']])->textInput(['placeholder' => "Subject"])->label(false); ?></div>

                    <div class="col-md-12"><?= $form->field($model, 'body', ['inputOptions' => ['class' => 'required valid', 'id' => 'message']])->textarea(['rows' => 6])->label(false); ?></div>

                    <div class="col-md-12"><?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
                            'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
                        ]) ?></div>

                    <div class="form-group">
                        <input name=" " type="submit" value="submit">
                    </div>

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

                <?php endif; ?>

Model:
public function contact($email)
{
    $content = "<p>Email: " . $this->email . "</p>";
    $content .= "<p>Name: " . $this->name . "</p>";
    $content .= "<p>Subject: " . $this->subject . "</p>";
    $content .= "<p>Body: " . $this->body . "</p>";
    if ($this->validate()) {
        Yii::$app->mailer->compose("@app/mail/layouts/html", ["content" => $content])
            //->setTo($email)
            ->setTo('[email protected]')
            ->setFrom([\Yii::$app->params['supportEmail'] => $this->name])
            //->setFrom([$this->email => $this->name])
            //->setFrom('[email protected]')
            //->setFrom([\Yii::$app->params['supportEmail'] => $this->name])
            ->setSubject($this->subject)
            ->setTextBody($this->body)
            ->send();

        return true;
    }
    return false;
}

Controller:
/**
 * Displays contact page.
 *
 * @return Response|string
 */
public function actionContact()
{
    $model = new ContactForm();
    if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
        Yii::$app->session->setFlash('contactFormSubmitted');
        return $this->refresh();
    } else {
        return $this->render('contact', [
            'model' => $model,
        ]);
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question