Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-03-29
5
Medium Priority
?
1,103 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

618 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