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

Upload image from frontend

Started by Muut Archive 10 years ago · 3 replies · 861 views
10 years ago

I want to provide a form for the user to upload a picture. Following the documentation I wrote the following header:

title: Images
form:
name: uploadImages
fields:

YAML
        type: file
        multiple: false
        destination: '@self'
        accept:
            - 'image/*'
buttons:
    -
        type: submit
        value: Submit

The the field to upload images and the submit button show correctly but if I press submit the image is not uploaded to location @self. Am I missing a process instruction or is the image uploaded to another place?

Thanks for your help.
Grimm.

10 years ago

How did you do? Cause I can't make my file typed field work.

10 years ago

I still could't solve the problem. Here is the .md-file is used (form.md, - - - escaped by ). It uses the display template form. I tried with different themes (clean blog, saturn and antimatter) but it doesn't help.
Is there another way to give the user a file upload? This functionaltity seems pretty basic - I feel like I am missing something ...

YAML
\```
title: Images
form:
    name: formular
    fields:
        -
            name: my_file
            type: file
            multiple: false
            destination: '@self'
            accept:
                - 'image/*'
    buttons:
        -
            type: submit
            value: Submit
\```
Upload images

Screenshot image upload

10 years ago

Not sure this will help as I have not used the file upload in the front end but here is my blueprint for a slideshow which uploads files in the admin side.

YAML
title: Slider
'@extends': default

form:
  fields:
    tabs:
      fields:
        advanced:
          fields:
            columns:
              fields:
                column1:
                  fields:
                    name:
                      default: modular/slider
                      '@data-options': '\Grav\Common\Page\Pages::modularTypes'
            overrides: 
              fields:
                header.template:
                  default: modular/slider
                  '@data-options': '\Grav\Common\Page\Pages::modularTypes'
        slider:
          type: tab
          title: Slider
          fields:
            header.slider:
              name: slider
              type: list
              label: Slider

              fields:
                .image:
                  type: file
                  label: Image
                  multiple: false
                  destination: 'self@/images'
                  accept:
                    - 'image/*'
                .title:
                  type: text
                  label: Header
                .text:
                  type: textarea
                  label: Text

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1349 9 years ago
Archive · by Muut Archive, 9 years ago
2 934 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2946 9 years ago
Archive · by Muut Archive, 9 years ago
3 1118 9 years ago