Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

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

Started by Yann 8 years ago · 4 replies · 1076 views
8 years ago

Hi,
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 ?

Thanks

8 years ago

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):

YAML
    - 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.

8 years ago

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'
accept:

  • '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.

6 years ago

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

Thanks for your help!

6 years ago

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

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1138 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 62 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 136 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 110 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 130 7 months ago