E
E
Eugene2018-12-06 10:28:56
Yii
Eugene, 2018-12-06 10:28:56

Why are there no validator messages?

Good afternoon. There is such a question. I decided to remake client-side validation into server -side validation
There is a form

The form
<div class="col-md-8">

                <?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' => 'Имя'])->label(false)?>
                        </div>
                        <!-- email -->
                        <div class="col-md-6">
                            <?= $form->field($model, 'emailU')->textInput(['class' =>'form-control main', 'placeholder' => 'Почта'])->label(false)?>

                        </div>
                        <!-- phone -->
                        <div class="col-md-12">
                            <?= $form->field($model, 'telephoneU')->textInput(['class' =>'form-control main', 'placeholder' => 'Телефон'])->label(false)?>
                        </div>
                        <!-- message -->
                        <div class="col-md-12">
                            <?= $form->field($model, 'textU')->textarea(['class' =>'form-control main', 'placeholder' => 'Текст сообщения', 'rows' =>15])->label(false)?>

                        </div>
                        <!-- submit button -->
                        <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="col-md-12 text-center">
                            <?= Html::submitButton('Отправить', ['class' => 'btn btn-style-one', 'name' => 'contact-button']) ?>
                        </div>
                    <!-- contact form end -->
                    <?php ActiveForm::end(); ?>
                </div>

                <?php endif; ?>
            </div>

Controller
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]);
    }

Well, the Messages model has its own rules
public function rules()
    {
        return [
            [['nameU','emailU', 'telephoneU', 'textU'], 'required'],
            [['text','textU', 'answer'], 'string'],
            [['viewed', 'idmess'], 'integer'],
            [['date'], 'safe'],
            [['emailU'],'email',  'message' => 'Введите корректный Email-адрес без пробелов и ошибок'],
            [['name', 'email','nameU' , 'textmess' , 'clientmail' , 'namemess'], 'string', 'max' => 250],
            [['telephone','telephoneU'], 'string', 'max' => 100],
            ['verifyCode', 'captcha']

        ];
    }

+ In the model, the Message method
public function Message()
    {
        if ($this->validate()) {
        $model = new Messages();
        $model->name = $this->nameU;
        $model->email = $this->emailU;
        $model->telephone = $this->telephoneU;
        $model->text = $this->textU;
        $model->save();
            return true;
        }
        return false;

    }

Validation mentally passes, that is, the form is not submitted until all the Rules are fulfilled. But no validation errors are displayed. Although in the documentation there, under each window, an error is displayed. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
D
Dmitry, 2018-12-06
@evgen9586

Good morning.
The reason is in the parameter 'fieldConfig' => ['options' => ['tag' => false]].
Remove it and everything will work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question