MODX Community

Formit: retrieve the values of a type="file" input field

Hi

This is one of my input strings

<input type="file" name="file[]" id="inputfile1" class="inputfile" value="[[!+fi.file0]]" />

(Note I have three type=“file” input lines all with name=“file”)

If formit happens to find errors in the other form input fields at validation, it does not appear to remember the values of the input fields with type=“file”. They are empty again. Why?

How do I make formit remember that value so that the user does not have to select that same file from his computer again?

Thanks for your help

Ludo

Try ajax upload, it will remember it.

I always suggest putting a validation layer in your front end using javascript in addition to back end validation. It just provides a better UX if nothing else with instant feedback if the form has been completed correctly.

I believe that’s a security limitation; it’s not possible to set the value for a file input because if you could, you could potentially upload arbitrary files from the user. That’s not possible to set from JavaScript either.

I tried that first, but was unable to get ajaxupload to work with webpack in zurb foundation.

Ludo

It’s funny I haven’t thought about that, because all other fields in my form have frontend validation. Turns out it’s not that difficult.

Thanks for the help.

Ludo