How rename automaticaly uploaded file from form with fields of the form

i created a form in front end.
I asked in this form : first name, last name, email and a file.
I would like to rename uploaded file with “last name”-name of file

How can i do this ?


The Grav docs include an example of setting email values from the form input. To apply this to the file name, a bit further down you’ll see that you can also apply this technique to the saved file prefix. It looks like this is not documented, but you can also set a filename property under the save form action.

So using the filename property, you would end up with something like this (adapted from one of my forms):

    - save:
        filename: "{{ form.value['lastname']|e|lower  ~ '-' ~ form.value['firstname']|e|lower ~ '.txt' }}"
        body: "{% include 'forms/data.txt.twig' %}"

I’d also put some kind of timestamp in the filename too, to ensure it is unique. I have something custom for this, but I think now this is simpler because there is a timestamp field in the forms plugin. I don’t have time to look into that right now, I’m sorry.

Thank you for your answer.
It was not exactly what i would like.

I would like to change name of joint documents downloaded by people filling my form.
i use field “file” in the form :
name: file
label: ‘Joint files’
type: file
multiple: true
destination: ‘@self
- ‘pdf’

If people send a pdf file, i would like rename file by using others fields of form.
Ex : “firstname-lastname.pdf”

Thank you for your help.

I’m trying to solve the same issue. Did you find a solution somehow?

Thanks for your help!

Sorry, i didn’t find any solution with GRAV.
From server, we created a Python script to scan csv file and rename file downloaded.