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

Add / remove file by frontend form

form plugins

Started by Tommy 5 years ago · 3 replies · 618 views
5 years ago

Hello,

I've modified user form (frontend) user_profile to add file field upload. Everything is working great. File is saved in folder. But I can't delete that added file by user_profile form. Am I doing something wrong or form plugin can't do that?

GetGrav # v1.7.24
form plugin # v5.1.3
login pugin # v3.6.0

user\plugins\login\pages\profile.md:

YAML
custom_file:
  type: file
  label: A Label
  multiple: false
  destination: 'page@:/test'
  random_name: false
  avoid_overwriting: true
  limit: 10
  accept:
    - image/*

user\config\plugins\login.yaml:

fields:

  • custom_file

user\accounts\user.yaml:

custom_file:
'user/pages/test/myfile.jpg':
name: myfile.jpg'
type: image/jpeg
size: 33461
path: 'user/pages/test/myfile.jpg'

last edited 10/27/21 by Tommy
5 years ago

@tomasz_s1,

Please note:

  • Don't ever change file below /user/plugins/* or /user/themes/*. Any changes made to plugin/theme files will be removed after an update of plugin/theme.
  • According the docs:

    The file field is intended to be used by configuration , theme , and plugins blueprints, NOT page blueprints . For pages, you should use the existing pagemedia field and then utilize the filepicker field to select the files.

Answer:
AFAIK (and Grav has more secrets I don't know off), the forms plugin does not provide an option to delete uploaded files.

Possible solution:

  • Create a plugin that handles event onFormProcessed. You will then have the ability to add your own logic.
5 years ago

I would like to let users add their own file only to read/delete by the owner of this file (that user). Destination of saving file is not important.
Do I have to write my plugin or is any GetGrav plugin? What is best solution to do it?

last edited 10/27/21 by Tommy
5 years ago

@tomasz_s1, You will have to write you're own custom plugin to handle the onFormProcessed event. Unless you can find one on the plugin repository that suits your needs (but I doubt you will).

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1136 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 61 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 134 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 110 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 129 7 months ago