Setup

Download the FixFileField Plugin from https://github.com/bleutzinn/grav-plugin-fixfilefield

To keep it simple the demo form consists of just 3 fields:

  • a mandatory Name field
  • a mandatory Attachment field
  • a non mandatory Images field

These fields use the standard validate.required and limit field attributes. To set a required minimum number of files to upload a new attribute lower_limit is used.

By using a combination of the field attributes validate.required, limit and lower_limit you can create a file field which basically says
"Hey, you don't need to upload any images but if you do make sure you upload at least x but no more than y images".

Form page source

The complete markdown code including the frontmatter as used in the page 'Form' looks like this:

---
title: Form
template: form
cache_enable: false
form:
    name: sign-up
    fields:
        name:
            label:  PLUGIN_FIXFILEFIELD.DEMO_TEXTS.NAME_LABEL
            type: text
            validate:
                required: true
        attachment:
            label:  PLUGIN_FIXFILEFIELD.DEMO_TEXTS.ATTACHMENT_LABEL
            type: file
            multiple: false
            accept:
                - application/pdf
            validate:
                required: true
            limit: 1
        images:
            label: PLUGIN_FIXFILEFIELD.DEMO_TEXTS.IMAGES_LABEL
            type: file
            multiple: true
            accept:
                - image/jpeg
                - image/png
            lower_limit: 2
            limit: 3
        honeypot:
            type: honeypot
    buttons:
        submit:
            type: submit
            value: Submit
        reset:
            type: reset
            value: Reset
    process:
        message: 'Thanks for signing up'
        display: thankyou
---

## FixFileField Plugin Demo

! Note: You are not signing up for anything; this is just a demo. However uploaded files **do get saved** to this server so do not upload any private data.