how to on changed page listener

Hi there.

I have a model "m". I want to execute some public static function every time I change the "update" page of the model "m". How can I do that?

My model "m" has many models "m2". I need the "id" of my model "m" to create a model "m2", so, I created the model "m" empty and I redirected to the "update" page of the model "m" to create the models "m2" with no problems (because in this point, I have the id of the model "m"). The problem is if I decide to close the web application or change to another page (without finish the "update"), the model "m" remains saved "empty" in the database (of course), so I need to delete that model if I change the "update" page and if the model "m" is empty.

With "model empty" I mean the model saved with id but no other attribute filled.

I hope you can help me. Thanks in advance

Take a look at DynamicForms by wbraganca

yii2-dynamicform

I believe this is what you are looking for

thank you very much, but that would be a lot of change in what I already have done in the “views”, I’m working with a web designer and I cannot do changes in the “views” without asking her and your solution requires a lot of changes in the “views”…

could be another alternative maybe?

I think you should change your processing workflow - store into DB only properly validated model attributes.

It’s almost impossible to ex-post decide whether stored data should or should not be removed from DB.

Ok, I’ll have to change everything to do it right. Thanks for your time.