Updating input fields of a form from PHP code executed on the server

What I am trying to accomplish is manipulating the content of the input fields of an ActiveForm which has already been rendered on the browser, from PHP code executed on the server under certain circumstances.

Being a newbie with using Yii, I thought about exploiting the ajaxValidation which is present in my ActiveForm as a hook where my code could decide whether or not to change the value of a field in the model AND as a result in the input fields of the ActiveForm.

But this is not the case, as I found, because the result of ActiveForm::validate is just an array of errors, in my case empty.

I could try and find a solution with AJAX and JS, but I think it won’t be as a reusable approach as one would want.

Is there any preferred way from Yii to refresh/update the input fields of an ActiveForm which has already been rendered on the browser, from PHP code executed on the server?

You’re asking to update an already rendered page in the browser from the server. You have two options. Setting up HTTP/2 to keep a connection open and to push updates and update via JS (includes much more work on the server-side and not readily available with Yii), or long polling. The server cannot update data already sent to the client when the connection is already close after the data is sent.