M
M
Mark2017-10-17 22:56:55
Yii
Mark, 2017-10-17 22:56:55

How to process form data through Yii2 widget?

Hello. There is a subscription form, it is located in the footer, so it needs to be processed on all pages where the current layout is used.
lc5BN.jpg
According to the information I found, it's best to do it through a widget. But I can't figure out how to implement it correctly.
Widget in this case will act as some kind of integrated controller? Does the processing logic need to be included in it? How to pass data to the form model, for example?
Thanks for answers.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2017-10-17
@slo_nik

Good evening.
Not necessarily through a widget.
If you use the form in a template, then the main thing is to transfer the model to the template.
And then as with the usual form.
You create an action in the controller that will process the data from the form, accept the data via ajax and process it. After that, you return a response, either a successful form submission or an error.

E
Evgeny Bukharev, 2017-10-17
@evgenybuckharev

1. Create a widget
2. In the run method, write the logic for processing data from the $_POST array
3. In the run method, render the view 4. Display the Profit
form in the view

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question