I am procesing a form inside a hook for product unpackaging and I’d like to prevent user page refresh once finished and the subsecuent form re-processing. It creates an action button at product stock card and open a jQuery window to let the user set the warehouse and the qty.
I tried to make a redirect when finished as Dolibarr do in all common object cards but I can’t modify HTTP headers at this level. I understand a class is not the right place for redirections, but I did not found a better place.
Where 3000 is the wait time in milliseconds before redirect (3000 = 3s) and you can remove it for an immediate redirect. However, note that this will trigger page refresh.
Also, if this is a third-party module, I suggest using the actions/hooks file instead of the module class file.
I use to apply such approach, but I was wondering about a cleaner solution because the risk of re-processng the form is still existing as well as you have to completely load the page to execute your code fragment.