Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Obtaining data on ASP 8 35
IF statment In Powershell 12 28
CSS Style Effect 2 18
Why is my $_POST not going to results page 10 35
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
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 …

763 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