Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  12] [ 4]  / answers: 1 / hits: 21474  / 13 Years ago, wed, july 27, 2011, 12:00:00

Okay so here's the scenario:



User is presented with form that contains file inputs.
User submits form.
Form does not pass validation/verification for one reason or another.
User is presented form with errors highlighted.
File inputs are now blank.



Question:



Is it possible to re-populate the file inputs with the paths to the files the user originally selected. A PHP solution would be ideal, but I'm also open to JavaScript solutions as well.


More From » php

 Answers
87

I think the short answer here is no. You can't repopulate file upload fields. However, you can work around it.



If a file has been selected and the form submitted, then you've already received the file. What you can do is keep a reference to the file on disk and put that in a hidden field and show a message to indicate to the user you still have their file uploaded so it does not need to be replaced/re-uploaded. When your form gets submitted again without a file, you can check for the hidden field value and use that to get your local copy of the file they uploaded in their last attempt.



The other way to do this is to either submit the form via ajax (using either flash or the iframe method for the file upload) or to do an ajax call to validate the form first, and then only submit as normal if valid (thus no form reload, no loss of file upload field data).


[#90982] Tuesday, July 26, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
katianatasham

Total Points: 293
Total Questions: 110
Total Answers: 103

Location: Saint Helena
Member since Mon, Jun 28, 2021
3 Years ago
katianatasham questions
Tue, Jul 20, 21, 00:00, 3 Years ago
Thu, Mar 18, 21, 00:00, 3 Years ago
Wed, Nov 25, 20, 00:00, 4 Years ago
Wed, Jun 24, 20, 00:00, 4 Years ago
Fri, May 15, 20, 00:00, 4 Years ago
;