M
M
MaikMain2018-08-13 20:53:45
Yii
MaikMain, 2018-08-13 20:53:45

How to make the "request a call" function. Yii2?

I'll explain the situation. There is a pop-up window, which is registered in layouts . It has 2 fields: name and phone.
How do I receive data, which controller or how in general? And where can I process it?

spoiler
Yii::$app->mailer->compose('callback', [
                'name' => $this->name,
                'phone' => $this->phone,
                ])
                ->setFrom([Yii::$app->params['adminEmail'] => $this->name]) /* от кого */
                ->setTo($emailto) /* куда */
                ->setSubject('Заявка обратного звонка с сайта') /* имя отправителя */
                ->setTextBody($this->body) /* текст сообщения */
                ->send(); /* функция отправки письма */

Where do I need to write this code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2018-08-14
@MaikMain

Wrap the submit form in Pjax and put it in a separate view, which you render in a modal window.
In the form, specify the address for processing, for example ['/site/contact'].
In the controller, process the data and render the same form (view) [$this->renderAjax('pjax-modal-form-view.php')].
To close the modal window upon successful submission, pass an additional parameter to the view, and in the view itself add js code, something like this:

if (isset($result) && $result){
  $this->registerJs("$('#myModal').hide()");
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question