?
Solved

Retaining form value for input type=file after refresh in Coldfusion

Posted on 2009-03-29
5
Medium Priority
?
1,113 Views
Last Modified: 2012-06-27
In Coldfusion, I am trying to retain the value of a input type=file (for uploading).  When validating my form, all entered values are returned upon submit accept the value for the input type=file field.

How do code to retain value enter or browsed by user or the input type='file' field?

<cfparam name="Form.FileToUpload" default="">
...
<cfif Len(Trim(Form.FileToUpload)) EQ 0>
  <cfset strError = strError & "<li type='square'>Enter or browse for Image to Upload.<br>">
</cfif>
...
<form name="entryForm" id="entryForm" action="entrypublic.cfm" method="post"  enctype="multipart/form-data">
...
<input type="file" name="Form.FileToUpload" value="#HTMLEditFormat(Form.FileToUpload)#" size="35" class="smalltext" tabindex="3" />
...
<input type="hidden" name="submitted" value="yes">
</form>

Open in new window

0
Comment
Question by:galengray
  • 3
4 Comments
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24015206
you can't.
not in cf or any other language - you can't pre-populate an input of type="file". this is a security feature of current HTML standard.

Azadi
0
 

Author Comment

by:galengray
ID: 24015244
Azadi,

How then do you explaln sites that do retain browsed info upon refresh or form validation?

Thanks for the prompt reply.  

--Galen
0
 
LVL 27

Accepted Solution

by:
azadisaryev earned 2000 total points
ID: 24015274
if you submit your form to ANOTHER page that does validation, and on that page tell user to press their browser's back button if there are errors, then when they do press the 'back' button, they will return to the from page, and they [usually] will still have all the info they have selected/typed in previously in the form, including their selection in the FILE input.

but you can't pre-populate a blank FILE input field.

if you are using CFFORM tag and your form submits to itself, you can try specifying preserveData="yes" to make the form display submitted values instead of default values. i an not sure if this works with <cfinput type="file">, though...

Azadi
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24070198
@galengray: how did it go? do you need mroe help with this?

Azadi
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question