We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25511
    • 13 Posts
    There seems to be a little bug on eForm snippet with file type inputs or then I'm just not getting it.

    <input name="demofile" id="demofile" type="file" eform="Wrong filetype:file:0:Supported filetypes are pdf, txt and doc:#LIST pdf,txt,doc" />
    


    When eForm throws validation error, all other inputs remember it's current value but every type file resets to blank.

    Any thoughts? [ed. note: Roope last edited this post 11 years, 6 months ago.]
    • The only way a file input field can be given a value is to select a file from the local file browser popup. In fact, if you run your page through an HTML validator, if the field has a value attribute it will fail validation. eForm cannot give it a value.

      You cannot modify the field's value with javascript, either. The only way to empty such a field if the user doesn't want to submit is to either clear the whole form, or use javascript to remove the field altogether then insert a new one.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 25511
        • 13 Posts
        Thanks for your reply Susan!

        Maybe I explained this bit badly but the problem is that when user fills the file input (selects a file from computer) and submits form, all values are cleared in all file inputs if validation error happens.

        Let's say that I have a form with three inputs: name and email as text input fields and one attachment as file input. User fills all three but email field doesn't contain valid email address and after submit form returns with validation error: your email address is not valid.

        Now after this validation message name and email fields still contain the user entered value but this one file input resets to blank -> entered value dissapears and user has to select attachment again from computer.

        So is this a bug or am I missing something with my markup?
          • 4172
          • 5,888 Posts
          As Susan said:

          The only way a file input field can be given a value is to select a file from the local file browser

          This means its not possible to fill the file-input again, after validation. The user has to select his files again.

          You can use an ajax-fileuploader, for example something like that: https://github.com/Jako/AjaxImageUpload, which uploads the files directly into a temp-folder on the server and stores the file-values into a SESSION-Var. After validation-success eform can move them to the target-folder.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
          • On validation errors, the field will be empty, because there is no way that field can be filled programmatically.

            It's done that way by browsers for security reasons; a malicious form could have a hidden file upload field to upload some sensitive file (like your passwords file) when you submit the form without you even knowing it.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 25511
              • 13 Posts
              OK, I got it now.

              I have to look for some preloader script like Bruno suggested.

              Thanks guys!