To allow end-users to upload images (or files) when they create a new page using my Add Page by Form plugin, I'm trying to change the destination of the upload. The challenge is that the destination is unknown until the form is submitted. That's because the destination is determined by the new page Title user input.
Changing the destination field value in Javascript has crossed my mind but it feels like a hack. I would rather do it 'the Grav way', that is within PHP using the events. The onFormProcessed event is too late since the image by then has been placed alongside the page containing the Add Page form by the Form plugin. So I was looking for some kind of onBeforeFormProcessed event. The most promising event which is fired before the image is moved from the temporary upload location to it's destination folder is the onFormValidationProcessed event.
The approach is to find the destination variable in the $event['form'] array and when it's value is @self change it to the desired location (being the new page folder). The finding part went okay but I'm stuck on how to change the value of destination.
Any hints are greatly appreciated!