Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple file upload field #81

Open
ger4003 opened this issue Sep 28, 2022 · 0 comments · May be fixed by #82
Open

Add support for multiple file upload field #81

ger4003 opened this issue Sep 28, 2022 · 0 comments · May be fixed by #82

Comments

@ger4003
Copy link

ger4003 commented Sep 28, 2022

With the following form configuration in place the submitted data values contain only the first selected file of the multiple file upload field attachments.

I have discovered that the underlying issue is how the __trustedProperties field value is created.

Form configuration

prototype(My.Package:Content.ApplicationForm) < prototype(Neos.Neos:ContentComponent) {
    renderer = Neos.Fusion.Form:Runtime.RuntimeForm {
            namespace = 'application_form'
    
            process {
                content = My.Package:Components.ApplicationForm

                schema = Neos.Fusion.Form:Runtime.SchemaCollection {
                    name = ${Form.Schema.string().isRequired()}
                    email = ${Form.Schema.string().isRequired().validator('EmailAddress')}
                    attachments = ${Form.Schema.arrayOf(Form.Schema.resource().isRequired().validator('Neos\Fusion\Form\Runtime\Validation\Validator\FileTypeValidator', { allowedMediaTypes: ['image/jpeg', 'application/pdf'] }))}
                    picture = ${Form.Schema.resource().isRequired().validator('Neos\Fusion\Form\Runtime\Validation\Validator\FileTypeValidator', { allowedMediaTypes: ['image/jpeg'] })}
                }
            }

            action {
                email {
                    type = 'Neos.Fusion.Form.Runtime:Email'
                    options {
                        senderAddress = ...
                        senderName = ${data.name}
                        replyToAddress = ${data.email}
                        recipientAddress = ...
                        subject = "..."
                        attachments {
                             multipleFileUpload = ${data.attachments}
                             singleFileUpload = ${data.picture}
                        }
                        text = "..."
                    }
                }
            }
        }
}

prototype(My.Package:Components.ApplicationForm) < prototype(Neos.Fusion:Component) {
    renderer = afx`
        <fieldset>
            <legend>Application form</legend>
        </fieldset>

        <Neos.Fusion.Form:FieldContainer field.name="name" label="Name">
            <Neos.Fusion.Form:Input>
        </Neos.Fusion.Form:FieldContainer>

        <Neos.Fusion.Form:FieldContainer field.name="email" label="Email">
            <Neos.Fusion.Form:Input 
                attributes.type="email" 
            />
        </Neos.Fusion.Form:FieldContainer>

        <!-- multiple file upload-->
        <Neos.Fusion.Form:FieldContainer field.name="attachments" label="Attachments">
            <input 
                name={field.getName() + '[]'} 
                type="file"
                multiple={true} 
            />
        </Neos.Fusion.Form:FieldContainer>

        <!-- single file upload-->
        <Neos.Fusion.Form:FieldContainer field.name="picture" label="Attachments">
            <Neos.Fusion.Form:Upload />
        </Neos.Fusion.Form:FieldContainer>
    `
}
@ger4003 ger4003 linked a pull request Sep 28, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant