P
P
po472021-04-28 16:02:13
Yii
po47, 2021-04-28 16:02:13

How to process form for page template (layouts/main.php)?

The form in the modal window should be used on all pages of the site, so we shove it into layouts.
The SiteController is used to process the form. The problem is that if it is in layouts/main.php , form processing through that controller is not done. If you push the form into site/index.php - everything works.
In uses, everything is the same, the problem is in processing.

As a matter of fact, as far as I understand, the form for the page template also needs to be processed in the SiteController and may not be rendered.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MikUrrey, 2021-04-28
@po47

If the form works the same everywhere and does not send information that depends on the current content of the page, then it is better not to mention it in the controllers.
And send the data either (elegantly) with AJAX, or (hardcore) inside the form, pass the current URL and return to it after the form is processed. That is, you still need to write a controller for it, but one and independent.

T
twopizza, 2021-04-29
@twopizza

<?php $form = ActiveForm::begin([
    'action' => '/your-controller/your-action'
]); ?>

And you write the action attribute on the form. And you will be able to choose which actual action of the controller to perform for its processing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question