Answer the question
In order to leave comments, you need to log in
Why can't he see Flash? Where did I go wrong?
In general, I send a message from the form to the database.
Here is the form
<?php if (Yii::$app->session->hasFlash('contactFormSub')): ?>
<div class="alert alert-success">
Ваше сообщение отправлено, в ближайшее время наши специалисты дадут Вам ответ на указнную вами электронную почту.
</div>
<?php else: ?>
<div class="contact-form">
<!-- contact form start -->
<?php $form = ActiveForm::begin(['id' => 'messages','options' => ['class' => 'row'], 'fieldConfig' => ['options' => ['tag' => false]]]); ?>
<!-- name -->
<div class="col-md-6">
<?= $form->field($model, 'nameU')->textInput(['autofocus' => true, 'class' =>'form-control main', 'placeholder' => 'Имя', 'required' => true])->label(false)?>
</div>
<!-- email -->
<div class="col-md-6">
<?= $form->field($model, 'emailU')->textInput(['autofocus' => true, 'class' =>'form-control main', 'placeholder' => 'Почта', 'required' => true])->label(false)?>
</div>
<!-- phone -->
<div class="col-md-12">
<?= $form->field($model, 'telephoneU')->textInput(['autofocus' => true, 'class' =>'form-control main', 'placeholder' => 'Телефон', 'required' => true])->label(false)?>
</div>
<!-- message -->
<div class="col-md-12">
<?= $form->field($model, 'textU')->textarea(['autofocus' => true, 'class' =>'form-control main', 'placeholder' => 'Текст сообщения', 'required' => true, 'rows' =>15])->label(false)?>
</div>
<!-- submit button -->
<div class="col-md-12 text-center">
<?= Html::submitButton('Отправить', ['class' => 'btn btn-style-one', 'name' => 'contact-button']) ?>
</div>
</form>
<!-- contact form end -->
<?php ActiveForm::end(); ?>
</div>
<?php endif; ?>
public function actionContacts()
{
$model = new Messages() ;
if ($model->load(Yii::$app->request->post()) && $model->message()) {
Yii::$app->session->setFlash('contactFormSub');
return $this->refresh();
}
return $this->render('contacts', ['model' => $model]);
}
public function Message()
{
$model = new Messages();
$model->name = $this->nameU;
$model->email = $this->emailU;
$model->telephone = $this->telephoneU;
$model->text = $this->textU;
$model->save();
}
Answer the question
In order to leave comments, you need to log in
You are using flash messages in a very strange way, I recommend:
https://www.yiiframework.com/doc/guide/2.0/en/runt...
But it should still work. And session normally works? Are you sure that
if ($model->load(Yii::$app->request->post()) && $model->message()) {
does it work? Try addFlash instead of setFlash
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question