Помогите пожалуйста разобраться с ошибкой, уже голову сломала... Вообще не пойму в чём может быть проблема..
У меня есть контактная форма:
<?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('Код')") ?>
<!-- <div class="wakeup__form-error">Неверный формат промокода</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">Неверный формат телефона</div>-->
</div>
<div class="wakeup__form-check-wrap">
<label class="wakeup__form-check" for="agreement">
<input placeholder="Код" class="wakeup__form-check-input" type="checkbox" id="agreement" name="agreement">
<span class="wakeup__form-check-placeholder"></span>
Согласен с <a href="/images/Usloviya_polozhenie_viktorini.pdf" download="Условия_и_Положения_Викторины.pdf" target="_blank">правилами Викторины</a>
</label>
</div>
<label class="wakeup__form-btn disabled" for="wake-up-submit">
Активировать услугу
<button id="wake-up-submit" hidden></button>
</label>
<?php ActiveForm::end(); ?>
<?php endif; ?>
Контроллер:
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,]);
}
}
Модель:
<?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>Имя: " . $this->name . ";</p>"
. "<p>\nТелефон: " . $this->phone . ";</p>")
->send();
return true;
}
return false;
}
}