Not working contact form, instead it is — Call to a member function formName() on null?

Please help to understand with an error, already a head broke... Do not understand what could be the problem..
I have a contact form:
<?php $form = ActiveForm::begin(['method' => 'POST', 'fieldConfig' => [
 'labelOptions' => [
 'class' => 'wakeup__form-name',
]
 ]]); ?>

 <div class="wakeup__form-group">
 <?= $form->field($model, 'name', ['inputOptions' => ['class' => 'wakeup__form-field', 'id' => 'code']])->label("$model->getAttributeLabel('Code')") ?>
<!-- <div class="wakeup__form-error">Invalid code</div>-->
</div>

 <div class="wakeup__form-group">
 <?= $form->field($model, 'phone', ['inputOptions' => ['class' => 'wakeup__form-field', 'id' => 'phone']])->label("$model->getAttributeLabel('+998(9X)XXX-XX-XX')") ?>
<!-- <div class="wakeup__form-error">Invalid phone</div>-->
</div>

 <div class="wakeup__form-check-wrap">
 <label class="wakeup__form-check" for="agreement">
 <input placeholder="Code" class="wakeup__form-check-input" type="checkbox" id="agreement" name="agreement">
 <span class="wakeup__form-check-placeholder"></span>
 I agree with <a href="/images/Usloviya_polozhenie_viktorini.pdf" download="Usloviyami.pdf" target="_blank">rules Quiz</a>
</label>
</div>

 <label class="wakeup__form-btn disabled" for="wake-up-submit">
 To activate the service
 <button id="wake-up-submit" hidden></button>
</label>
 <?php ActiveForm::end(); ?>

 <?php endif; ?>


Controller:
public function actionIndex()
{
 $model = new AppointmentForm();
 if ($model->load(Yii::$app->request->post()) && $model->appointment(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('contactFormSubmitted');
 return $this->refresh();
 } else {
 return $this->render('index', ['model'=> $model,]);
}
 }


Model:
<?php

namespace app\models;

use Yii;
use yii\db\ActiveRecord;

/**
 * This is the model class for table "system_news".
*
 * @property string $name
 * @property string $phone
*/
class AppointmentForm extends ActiveRecord
{
 public $name;
 public $phone;

/**
 * {@inheritdoc}
*/
 public static function tableName()
{
 return 'system_appointment';
}
/**
 * @return array the validation rules.
*/
 public function rules()
{
 return [
 // name, email, subject and body are required
 [['name', 'phone'], 'required'],
];
}

/**
 * Sends an email to the specified email address using the information collected by this model.
 * @param string $email the target email address
 * @return bool whether the model passes validation
*/
 public function appointment($name)
{
 $content = "<p>Name: ". $this->name . "</p>";
 $content .= "<p>Phone: ". $this->phone . "</p>";
 if ($this->validate()) {
Yii::$app->mailer->compose([
 "@app/mail/layouts/html","content" => $content
])
//->setTo($email)
->setTo('swallowsveta97@yandex.ru')
 ->setFrom([\Yii::$app->params['supportEmail'] => $this->name])
 ->setTextBody("<p>Name: ". $this->name . ";</p>"
 . "<p>\Telefon: ". $this->phone . ";</p>")
->send();

 return true;
}
 return false;
}
}
April 3rd 20 at 17:25
0 answer

Find more questions by tags Yii