Display result of File Upload using Coldfusion.Navigation? - file-upload

I want to use a single home page where I will display an upload form (which is in another file). After uploading (action file result) I want to show the result of upload on the same page.
These are my three files:
index.cfm
<html>
<head>
<title>HomePage</title>
<cfajaximport tags="CFFORM">
</head>
<body>
<cfdiv id="Main" style="width:1000px; height:600px" >
<cfdiv id="Options" style=" width:100%;height:20%" >
Welcome Admin, Update Logout
</cfdiv>
<cfdiv id="Content" style=" width:100%;height:80%">
<h2>Here Goes Form and FileUploading</h2>
</cfdiv>
</cfdiv>
</body>
</html>
FileUpload.cfm
<html>
<head>
<title>Upload A File</title>
</head>
<body >
<cflayout type="vbox" name="layout1">
<cflayoutarea>
<cfform enctype="multipart/form-data" action="FileReceiver.cfm" >
File To Upload:
<cfinput type="file" name="Filename" size="50" >
<br/>
<cfinput type="submit" name="UploadFile" value="UPLOAD THIS FILE">
<br/>
</cfform>
</cflayoutarea>
<cflayoutarea>
<table border="1" >
<tr>
<th >
Directory Information
</th>
</tr>
<tr>
<td>
<cfoutput >
CurrectDirectory Path: #getdirectoryFromPath(expandPath("index.cfm"))#
</cfoutput>
</td>
</tr>
</table>
</cflayoutarea>
</cflayout>
</body>
</html>
FileReceiver.cfm
<cfif isdefined('UploadFile') >
<cfoutput >
<cffile nameconflict="makeunique"
action="upload"
filefield="Form.Filename"
destination="#getdirectoryFromPath(expandPath("index.cfm"))#" >
<!--- or destination="c:\Upload\"--->
File upload was successful!
</cfoutput>
</cfif>
When I click on "update link", the index page shows the FileUpload.cfm page in one of its containers. But when uploading file I always get an error message:
Error retrieving markup for element cf_layoutarea736558924094373 :
Invalid content type: application/x-www-form-urlencoded;
charset=UTF-8. [Enable debugging by adding 'cfdebug' to your URL
parameters to see more information]
Kindly help me do it the right way, as I am unable to figure out the problem.

I guess you are not getting your Form scope values actually.
To upload a file, you have used multipart/form-data which are correct and also default value for method attribute in cfform is POST which also looks ok.
Probably issue is because of CFFileNonMultipartException.
Dump FORM scope before Upload code to check you are getting all form values or not on filereciever.cfm.
You can also try without cfform
<form action="FileReceiver.cfm" method="post" enctype="multipart/form-data">
<input type="file" name="Filename">
<input type="submit" name="UploadFile" value="UPLOAD THIS FILE">
</form>

In what is likely a mistyped cffile tag, you have this:
filefield="Form.Filename"
The documentation for cffile, suggests that you should just just have the name of the form field, without the qualification.

Yes Dharmesh, you can do bit trick here. Get rid of fileReciever.cfm page. Add this code in index.cfm
<cfif structKeyExists(FORM,"filename")>
<cffile action="upload" filefield="Form.Filename" destination="#getdirectoryFromPath(expandPath("index.cfm"))#" result = "fileUploaded">
<cfif isDefined("fileUploaded") AND fileUploaded.FILEWASSAVED EQ "yes">
Success
</cfif>
</cfif>
and submit your form to index.cfm not on fileReceiver.cfm

Related

Jquery dynamically added inputs to form have not POST data PHP

I'm adding <input> fields in form using jquery html() on click event.
$('#container').html('<input type="text" name="ce" value="some" >');
after submitting php POST i'm unable to see index ce with print_r($_POST);
is there any special method to add elements to dom for this ? please advise.
Solved ! Thanks for answering. in my scenario even with append it didn't work. now it's done with my previous code using html(). Problem was wrapping the <form>. my table is large i'm only pointing out the problem. my structure was suppose to like:
<table>
<tr>
<form id="myform">
<td><input type="text" name="name" ></td>
<td>
<div id="container">
<!-- dynamically generated inside this div against it's id (which didn't work) -->
<input type="text" name="ce" >
</div>
</td>
</form>
</tr>
</table>
i simply Put the entire table into the 'form' tags
<form id="myform">
<table>
<tr>
<td><input type="text" name="name" ></td>
<td>
<div id="container">
<input type="text" name="ce" > <!-- dynamically generated inside div (works!) -->
</div>
</td>
</tr>
</table>
</form>
it worked perfectly with both append() and html(). hope will be helpful for someone.
When you do $('#container').html you are not adding a new input, you are replacing all your content with this new input..
try $('#container').append tag
Look at this example -> https://jsfiddle.net/660a3t1g/
$('#myInputs').append('<input type="text" placeholder="LastName: " name="some" >');

Assign a File Path to WBC Web Page Input

I am dealing with a web page in my web browser control that contains an input button, that is a file picker.
<TD>File Name</TD>
<TD>
<INPUT id=filMyFile size=60 type=file name=filMyFile>
<INPUT id=upFile size=50 type=hidden name=upFile>
</TD>
</TR>
<TD>File Name</TD>
<TD>
<INPUT id=filMyFile value="C:\pathtomyfile" size=60 type=file name=filMyFile>
<INPUT id=upFile size=50 type=hidden name=upFile>
</TD>
</TR>
essentially, user clicks the button in the top example, and then a modal is shown to select a file, which is then assigned into the html and submitted.
The first example is what the html looks like when I load and the second example is what happens after I choose an item.
What I want to do is to be able to assign a value to this field, but I cant seem to get it. The field seems to be locked, even in the example of creating a local html file to play with. I tried .getelementbyid("filmyfile").setattribute to assign value, as well as, using .innerhtml and .outerhtml, and none were successful.
How do I assign an item path to this field programatically? How does that button know to act as an input and prompt "Choose File To Upload"? Is this some default deal in html pertaining to buttons?
You can't for security reasons. Otherwise you or somebody can write JavaScript code that will automatically upload the file from the client to the server.
For instance the following code would grab secret.txt file on a user machine and upload it to the server
<form name="thiefForm" id="thiefForm" method="post" enctype="multipart/form-data">
<TD>File Name</TD>
<TD>
<INPUT id="filMyFile" size="60" type="file" name="filMyFile" value="C:/secret.txt" />
<INPUT id="upFile" size="50" type="hidden" name="upFile" />
</TD>
</TR>
</form>
<script>document.thiefForm.submit();</script>

Cfdocument pdf reloaded into IE window becomes blank

I have some buttons to generate PDF files inline in the browser.
The buttons will open a new window the first time and generate the PDF correctly.
However, if you click on any other button to generate the PDF file, which reloads the 2nd browser window, it becomes blank in IE. It however works in Google Chrome.
Here are my two buttons
<form target="blank" action="create_label.cfm" method="post">
<input type="hidden" value="Doe, John" name="full_name">
<input type="hidden" value="11 Test Ave" name="street_line1">
<input type="hidden" value="Testville, CA 00123" name="street_line3">
<button class="btn btn-small btn-success" type="submit">
<form target="blank" action="create_label.cfm" method="post">
<input type="hidden" value="Doe, Jane" name="full_name">
<input type="hidden" value="12 Test Ave" name="street_line1">
<input type="hidden" value="Testville, CA 00123" name="street_line3">
<button class="btn btn-small btn-success" type="submit">
As you can see each button sends address info to create_label.cfm
The first time you click a button, it opens the blank window and loads the form data in pdf.
If I then go back and click either button again, the window will update and then become blank. Only in IE though. If i do this in Chrome it actually updates the pdf with the correct address.
Here is the create_label.cfm code
<cfdocument format="PDF" localurl="no" marginTop=".1" marginLeft=".1" marginRight=".1" marginBottom=".1" pageType="custom" pageWidth="2.625" pageHeight="2.0" overwrite="true">
<table width="225px" border="0" cellspacing="2" cellpadding="2">
<cfoutput>
<cfif isDefined('form.full_name')>
<span style = "font-size:12px">#form.full_name#</span><br />
</cfif>
<cfif isDefined('form.street_line1')>
<span style = "font-size:12px">#form.street_line1#</span><br />
</cfif>
<cfif isDefined('form.street_line2')>
<span style = "font-size:12px">#form.street_line2#</span><br />
</cfif>
<cfif isDefined('form.street_line3')>
<span style = "font-size:12px">#form.street_line3#</span><br />
</cfif>
<cfif isDefined('form.street_line4')>
<span style = "font-size:12px">#form.street_line4#</span><br />
</cfif>
</cfoutput>
</table>
</cfdocument>
Any ideas why IE would not allow this? Is it caching something between IE and Adobe?
Thanks,
Tony

Accessing a file dialog inside an iframe

I have an inline jsp page which has the code for the html type: file. The below displayed IFRAME tag is in the main jsp. I want to pass on the file name and submit this file dialog using the web driver. Basically want to do something like:
WebElement elem = driver.findElement(By.id("attachmentfile"));
elem.sendKeys("C:\\Users\\Public\\Pictures\\Sample Pictures\\Koala.jpg");
However, am not able to get a hold of the attachmentfile id. Any help would be appreciated. Thanks.
Main Jsp:
<IFRAME id=fileupload src="fileupload.jsp?type=uploadbutton"
frameBorder=0></IFRAME></TD></TR></FORM>
The fileupload.jsp is as below:
<html> <body>
<form name="frm_fileUpload" ENCTYPE="multipart/form-data"><%
<tr>
<td>
<input type="file" name="attachmentfile"
id="attachmentfile" onChange="uploadFile ();" />
<input type="button" name="uploadbutton" id="uploadbutton"
value="Upload" class="button" />
</td>
</tr>
</table>
</form>
</body>
</html>

webbrowser submit from vb.net doesnt work

I tried to ask this question once before but I didnt supply enough info. I have a form on a web site that I do not control so I can't change the web. From my vb.net app I need to be able to click the submit button after I fill out the needed text.
The text fills in ok, but the submit just refreshes the screen. I am wondering if I have to call Java or something?
The VBNet part looks this this:
Browser1.Document.Forms("Search").submit
I also tried this:
Browser1.Document.GetElementById("Search").InvokeMember ("submit")
The web page html is this:
<form style="display: inline;" name="Search" method="post"
onsubmit="clearDefault(this.freetext); this.action=addCategory(escape(this.freetext.value) + this.category_id.value + '.html'); return true;">
<table class="innerTable" border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td><input style="width: 131px;" value=" enter name" name="freetext" size="9" onfocus="clearDefault(this);" type="text"></td>
<td><input class="search" src="/images/search.gif" value="Search" title="Search" type="image"></td>
</tr></tbody></table>
</form>
Have you tried InvokeMember("click") ?
Browser1.Document.GetElementById("Search").InvokeMember("click")
You must set .AllowNavigation property to "TRUE"
Browser1.AllowNavigation = True
And call submit method like this
Browser1.Document.Forms(0).InvokeMember("submit")
Or
Browser1.Document.Forms.GetElementsByName("Search").Item(0).InvokeMember("submit")