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.
-
- 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?
-
- 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.
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.
-
- 13 Posts
OK, I got it now.
I have to look for some preloader script like Bruno suggested.
Thanks guys!