L
L
Light7772016-02-14 16:01:15
Yii
Light777, 2016-02-14 16:01:15

Why is the view not rendering in Yii2?

Why doesn't the view change when I press the SUBMIT button?
The letter is created in the runtime/mail folder.
The logs say that it is redirected to thanks.php, but in fact nothing happens
Contact form code in the contact.php view

<?php $form = ActiveForm::begin(['id' => 'contact-form',
                'options' => ['class' => 'contact-form page-margin-top'],]); ?>
                <div class="row">
                    <fieldset class="column column-1-2">

                        <?= $form->field($model, 'name')->label(false) ?>

                        <?= $form->field($model, 'email')->label(false) ?>

                        <?= $form->field($model, 'subject')->label(false) ?>
                    </fieldset>
                    <fieldset class="column column-1-2">

                        <?= $form->field($model, 'body')->textArea(['rows' => 6])->label(false) ?>
                    </fieldset>
                </div>
                <div class="row margin-top-30">
                    <div class="column column-1-2">
                        <p class="description t1">Наш менеджер свяжется с Вами в ближайшее время</p>
                    </div>
                    <div class="column column-1-2 align-right">
                        <?= Html::submitInput('ОТПРАВИТЬ', ['class' => 'more active', 'name' => 'submit']) ?>
                    </div>
                </div>

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

Controller code
public function actionContact()
    {
        $model = new ContactForm();
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
                //$this->redirect(Url::toRoute('/site/index'));
                Yii::trace('start calculating average revenue');
                return $this->render('thanks');               
               // Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
            } else {
                Yii::$app->session->setFlash('error', 'There was an error sending email.');
            }

           // return $this->refresh();
        } else {
            return $this->render('contact', [
                'model' => $model,
                ]);
        }
    }

Log
24ac4ac4e7f141688e7c2cec3d068975.PNG

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Natarov, 2016-02-14
@HanDroid

Try replacing this in the controller with:
Show like this.

// показывает файл "@app/views/site/license.php"
echo \Yii::$app->view->renderFile('@app/views/site/license.php');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question