0

I have a HTML file field <input name="File" id="FileName" type="file"/>. When I submit the form, I do receive the file, all fine. However, when I validate the user's input and cannot accept the values provided, I will need another round trip. As usual, I will redisplay the form plus error messages.

For text field or textarea I can set the (already) provided value, e.g. by value or just echo the value in the textarea. How could I do the same for file fields? I want to avoid that the user always has to reselect the file in the browser.

-- added --

Comments below are right - there are workarounds described in the mentioned SO questions:

  1. PHP remember file field contents
  2. Can you re-populate file inputs after failed form submission with PHP or JavaScript?
  3. Restoring the value of a input type=file after failed validation
3

1 Answer 1

1

This is not possible - you have to store the file on the server to do this. Then you can show the user a short info about the already stored file and the option to upload a new file or delete the file

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, seems to be right, was trying to store the path via Js, but even this failes: onChange= "alert( document.getElementById('FileName').value );" does provide a fake path, not the original upload path.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.