XForms/Multiple Uploads


You would like the user to be able to attach multiple files to a form.


We will use the <xf:repeat> around the upload control:

Sample SourceEdit

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events"
    xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
        <title>XForms Upload Multiple Simple</title>
            <xf:instance xmlns="" id="save-data">
                        <MyFile filename="" mediatype="" size=""></MyFile>
            <xf:instance id="file-upload-template" xmlns="">
                <MyFile filename="" mediatype="" size=""></MyFile>

        <p>Demonstration of how to use the repeat element to get multiple uploads.</p>
            <legend>Add multiple attachments</legend>
            <xf:repeat ref="instance('save-data')/Files1/MyFile" id="repeat-1">
                <xf:upload ref=".">
                    <xf:filename ref="@filename"></xf:filename>
                    <xf:mediatype ref="@mediatype"></xf:mediatype>
                    <xxforms:size ref="@size"></xxforms:size>
                    <!-- Note the event after upload could add a new row -->
                <xf:trigger ref="instance('save-data')/Files1/MyFile[2]">
                    <xf:delete ev:event="DOMActivate"
                <br />
                <xf:label>Add Attachment</xf:label>
                <xf:insert ev:event="DOMActivate" ref="instance('save-data')/Files1/MyFile"
                    origin="instance('file-upload-template')"> </xf:insert>


Sample User InterfaceEdit

upload multiple attachments

User interface notesEdit

  1. The delete trigger will only be visible after the second upload is shown.
  2. This interface shows the file name and size in bytes. The mime-type could also be shown
  3. You can add any number of files
  4. You can delete any row by selecting the "Delete" button
  5. You can re-add a file using the red X

The files will be uploaded to the server in an async process.

Tested on Orbeon 4.3