Solved

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

Posted on 2009-03-29
5
1,057 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
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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now