How to save form data and uploaded files into the same unique subdirectory?

The forms plugin allows us to use the save action, which will place the form data in a file with a timestamp of our own choice within the user/data directory. That’s fantastic. The file input field allows us to chose a destination, which boils down to either using @self, meaning that the files will be saved where the page’s template.md file is located, or to hand in a path to a directory. This is nice.

However, what I’m trying to achieve is this:

  • Save the form AND its associated uploaded files in the same directory
  • There should be one directory for each submitted form and it should therefore have a unique name (like the file saved by save does)

In other words, I would need to be able to:

  1. Somehow tell the save action to create a subdirectory with a certain format, just like we can define the timestamp/ID format for the file right now
  2. Use that same directory name (format string) in the destination property for the file field

Is this possible? Is there any other way to achieve the desired result? Or will I have to create/modify a plugin?

EDIT: Alternatively, is there any other way to associate an uploaded form with the files uploaded through it, so other scripts can later make that connection and show the form data and the uploaded files for a given submission?

Hi Julien,

Did you manage to resolve the issue of form text & attachments into a unique folder?

I am facing the same issue.

Many thanks,

Peter.

Unfortunately, not yet. I’ve created an issue on Github in late 2018, with the latest reply from the Grav team in early 2019 stating that they might have an idea on how to implement this. However, ever since there hasn’t been any updates.

Let me know if you manage to get this to work, I’m also still interested in a solution.

In what aspect is the Add Page By Form Plugin failing to achieve this? Assuming you tried it?

Did not think to try that one thanks bleutzinn.

Will explore.

Peter.

Hello, this topic is really near of my actual project
in my local enviroment

Ubuntu 20.04.1 LTS
XAMPP for Linux 7.2.7
I could create a file out the user/data and send also the upload files to the same folder. By using in the form configuration

  • proccess

    save:
    filename: “…/…/pages/XXXXXX”
    Once i upload to the produccion server
    i got this error

    Server Error

Sorry, something went terribly wrong!

0 - Creating directory failed for
/######/public_html/user/data/task/…/…/pages/

as i understand is trying againg to save inside de user/data
folder.
if have some suggestion i Will aprecciate.