CFFILE upload - insert file location into SQL db at the same time? - sql

I have a little page that has a form with a few fields in it. Also included is a file upload function. I need to be able to have the filename of the file being uploaded to be inserted into the 'sURL' field, when the form is submitted. (The sURL field can be populated automatically with this filename or can also be manually entered if it is an external URL). I have looked at other people with this issue and there seems to be no straightforward fix? Is anyone able to shed some light?
<html><head>
<title>New Survey Entry</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
function check ( form )
{
if (form.ul_path.value == "") {
alert( "Please select the file to upload." );
form.ul_path.focus();
return false ;
}
return true ;
}
</script>
<CFIF NOT isDefined("dir")>
<CFSET dir = "">
</CFIF>
<CFIF NOT isDefined("clientFile")>
<CFSET clientFile = "">
</CFIF>
<CFQUERY NAME="getpub" DATASOURCE="testpage" DBTYPE="ODBC">
SELECT *
FROM surveypubs
ORDER BY sGroup asc
</CFQUERY>
<h2><center>NEW SURVEY ENTRY</center></h2>
<table cellpadding="3" cellspacing="3" class="font13">
<cfoutput>
<form name="input" enctype="multipart/form-data" action="index.cfml?cat=test&page=insertSurvey" method="post">
<tr>
<td valign="middle" align="left"><b>Year:</b></td>
<td colspan="3"><input name="sYear" type="text" size="8" value="<CFOUTPUT>#year(now())#</CFOUTPUT>"><input name="sYear_required" type="hidden" value="You must enter a Year."></td>
</tr>
</cfoutput>
<tr>
<td valign="middle" align="left"><b>Group:</b></td>
<td colspan="3"> <select name="sGroup">
<option value="">--- Select One ---</option>
<cfoutput query="getpub"><option value="#sGroup#">#sGroup#</option></cfoutput>
</select> <br> Don't see the Survey Group? Click here to add.
</td>
</div><br><br>
</tr>
<tr>
<td valign="middle" align="left"><b>Title:</b></td>
<td colspan="3"><input name="sTitle" type="text" size="85"><input name="sTitle_required" type="hidden" value="You must enter a Title."></td>
</tr>
<tr>
<td valign="middle" align="left"><b>Comment:</b></td>
<td colspan="3"><input name="sComment" type="text" size="85"></td>
</tr>
<tr>
<td valign="middle" align="left"><b>URL:</b></td>
<td colspan="3"><input name="sURL" type="text" size="85"></td>
</tr>
<td valign="bottom" align="left"><b>URL Type:</b></td>
<td colspan="3">
<input type="radio" name="surlType" value="0" checked> Internal <input type="radio" name="surlType" value="1"> External</td>
</tr>
<cfoutput>
<input name="dateAdded" type="hidden" value="#dateformat(now(),"mm-dd-yyyy")#">
</cfoutput>
<tr>
<td></td>
<form action="/index.cfml?cat=test&page=inputSurvey" method="POST" enctype="multipart/form-data" name="upload_form" id="upload_form" onsubmit="return check(this);">
<CFIF structKeyExists(form, "ul_path") and len(form["ul_path"])>
<CFFILE ACTION="UPLOAD" FILEFIELD="ul_path" DESTINATION="D:\testpage\docs\" NAMECONFLICT="OverWrite">
<CFSET ClientFilePath = "#clientDirectory#\#clientFile#">
</CFIF>
<td colspan="3" align="left">Click on the Browse button to select the file to Upload:<br>
<input type="file" name="ul_path" id="ul_path" style="height: 22px;width: 350px;" value=""></td>
</tr>
<tr>
<td></td>
<td colspan="3" align="center"><input type="submit" name="submit" value="Submit"> <input name="clear" value="Clear" type="reset"> <input type="button" name="back" value="Back" class="input" onClick="javascript:history.back();"></td>
</tr>
</table>
</form>
<cfif isDefined("CFFILE.ClientFile")>
<cfset form.sURL = "#CFFILE.ClientFile#">
<cfelse>
<cfset form.sURL = "null">
</cfif>
<cfoutput><input type="hidden" name="sURL" id="sURL" value="http://testpage.com/docs/#ClientFile#"/></cfoutput>
</form>
</body>
</html>

Use the result attribute of cffile, this will then give you a structure of data about your upload, including the directory the file was stored in as well as the file name. Add result='moo' to your cffile call and then do a cfdump of moo to see all the data.
Check out this link for more info on what is returned in result

I sense that what you are trying to do is not being answered here. What you seem to be trying to do is on the client before the file is uploaded. You wish to collect the name of the file the user has chosen from his or her file system and using JS populate some other form field - which may contain the name of the file or possible some URL value or something else provided by the user.
That's different from collecting the name of the form after it is submitted because it runs afoul of browser protections. I really don't think there's an adequate solution in JS to this. You might find a solution that works in some browsers but I doubt it will be consistent.
I could be wrong of course. I'd be glad to have someone show me a solution.

Related

I want to extract a text string on the webpage which is written in the form of table, but I am getting null in return

WebElement e5 = d1.findElementByXPath("/html/body/div[1]/div[3]/div/div[1]/form/div/div[1]/div/table/tbody/tr[4]/td[2]");
String a = e5.getText();
System.out.println(a);
_____________________________________________________________________________
I have used getText method. The data is stored in the table, so the strategy which I am making use of is that first of all i want to get to the location of that data using xPath funda and then I need to extract the data corresponding to that location. Can anyone suggest a better way to do so.Thanks in advance.
pls find below the html:
<div class="wrapper">
<form method="post" action="">
<input id="_csrf" type="hidden" value="psJdnI5AnxjGqT2knrZG" name="_csrf">
<div class="innercontainer">
<div class="leftpanel">
<h2>MY ACCOUNT</h2>
<div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<tr>
<td>
<strong>Membership ID:</strong>
</td>
<td>2800000101</td>
</tr>
<tr>
<tr>
<tr> </tr>
<tr>
</tbody>
</table>
</div>
</div>
<div class="rightpanel">
</div>
</form>
</div>
html page added above. Kindly suggest some alternative
You need to clean up your Xpath, however this should help
WebElement tableText = driver.findElement(By.xpath("yourXpath"));
String actualText = tableText.getAttribute("textContent");
System.out.println(actualText)

Need Help to get value of selected item from Select Dropdown list in cfquery under insert query

Form:
<!-- Sign up FORM -->
<cfoutput>
<form method="post" action="HomeShow_submit.cfm">
<input type="hidden" name="UserID" value="#RemoveChars(CGI.Auth_User, 1, Find('\', CGI.Auth_User))#">
<input type="hidden" name="Fname" value="#User.fname#">
<input type="hidden" name="Lname" value="#User.lname#">
<input type="hidden" name="Year" value="#DatePart('yyyy', Now())#">
<table width="600" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<th colspan="2" scope="col" class="Header" align="center">Home Show Sign Up Form</th>
</tr>
<tr>
<th align="left" class="red">Shifts</th>
<td><select name="ShiftsList">
<option value="" selected> ... select a Shift</option>
<cfloop query="ShiftsList">
<option value="#ShiftsList.ShiftDetails#">#ShiftsList.ShiftDetails#</option>
</cfloop>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" NAME="SubmitForm" value="Submit"></td>
</tr>
</table>
</form>
</cfoutput>
ActionPage
<cfquerydatasource="HomeShow" name="InsertHomeShow">
INSERT INTO HomeShow
(UserID,
Fname,
Lname,
Year,
ShiftID
)
VALUES
('#Form.USERID#',
'#Form.Fname#',
'#Form.Lname#',
'#Form.Year#'
?
)
</cfquery>
Question: This is where I need help, suppose we choose option with value =1 i.e. Friday March 20th 10.00 a.m to noon. I want to get value i.e 1 in Insert statement. So What I can write in side Insert statement to get that value.
Got it! Some suggestion helped me a lot finding the answer!!!
<!--Form -->
<tr>
<th align="left" class="red">Shifts</th>
<td><select name="ShiftsID"> <cfloop query="ShiftsList">
<optio value="#ShiftsList.ShiftID#">#ShiftsList.ShiftDetails#</option>
</cfloop>
</select>
</td>
</tr>
<!-- Actionpage-->
<cfquery datasource="HomeShow" name="InsertHomeShow">
INSERT INTO HomeShow
(UserID,
Fname,
Lname,
Year,
ShiftID
)
VALUES
('#Form.USERID#',
'#Form.Fname#',
'#Form.Lname#',
'#Form.Year#',
'#Form.ShiftsID#'
)

POST request not working in form

I'm trying to submit some form using POST method. Here is par of form:
<form action="interlopers.php" mehod="post" id = "interlopersForm" name="interlopersForm" onsubmit="return validateInterlopersForm()">
<table border="0">
<tr>
<td> <label for="ast_num" > Ast. num </label> </td>
<td> <input type="text" name="ast_num" id = "ast_num"
value="<?php if(isset($_REQUEST['ast_num'])) { echo htmlentities ($_REQUEST['ast_num']); } ?>"
size="6"> </td>
</tr>
<tr>
<td><label for="cut_off"> Cut-off </label></td>
<td><input type="text" name="cut_off" id="cut_off" size="6" ></td>
</tr>
<tr>
<td><label for="data"> Data </label></td>
<td><input type ="checkbox" name="data" id = "dataSDSS" value="SDSS" checked> SDSS <br>
<input type ="checkbox" name="data" id="dataWISE" value="WISE" checked > WISE <br>
<input type ="checkbox" name="data" id = "dataSp" value="Sp" checked> Taxonomy</td>
</tr>
<tr>
<td> <label for="isFinalStep"> Just interlopers? </label> </td>
<td> <input type = "checkbox" name="isFinalStep" id = "isFinalStep"> </td>
</tr>
<tr> <input type="hidden" name="submitted" value="1"> </tr>
<tr>
<td colspan="2" align="center"> <input type="submit" value="Calculate" > </td>
</tr>
</table>
</form>
But, instead of getting POST request im getting GET request. I'm using apache server and php5 on Ubuntu. I tried this on local-server and on remote host, but still GET instead of POST.
Change mehod="post" to method="post".
You wrote wrong.

Input field is filled, but content is not saved using Selenium IDE

Using Selenium IDE, I'm able to fill an input field (using "type" command), but when I "save" the value, this value is lost. Doing the same by hand, everything works fine.
Any hint to solve this issue? I've already tried using typeKeys command.
The code inside the target page is:
<!-- language-all: lang-html -->
<div id="editDiv" class="editDialog">
<table cellspacing="0" width="100%">
<tbody>
<tr>
<td width="25%" style="">period</td>
<td align="right" width="25%" style="padding: 6px;">
<input id="period" type="text" onblur="changeValue(this.id, this.value, undefined)">
<br>
<label>da 0 a 9</label>
</td>
</tr>
</tbody>
</table>
<table cellspacing="0" width="100%">
<input type="button" value="Save" onclick="applyChanges()">
<input type="button" value="Cancel" onclick="removeEditDialog(false)">
</div>
To help more on this issue:
function changeValue(id, value, paramPos) {
var par = tempGlobalParams[id] ? tempGlobalParams[id] : tempGlobalPaintingsParams[paramPos][id];
if(checkRules(id, value, paramPos)){
par.custom = value;
}

wgetting a forum as a registered user

I want to sample the main page of a forum to do some statistics. The main page is only visible to registered members. How would I download it using wget? I tried logging in via a browser, then passing that browser's cookie file to wget, but it doesn't work.
EDIT: Here's the login form code:
<table border="0" cellpadding="3" cellspacing="1" width="100%">
<tr>
<td colspan="2" align="center"> </td>
</tr>
<tr>
<td width="45%" align="right"><span class="gen">User:</span></td>
<td><input type="text" name="username" size="25" maxlength="40" value="" class="post2" id="focus" onFocus="Active(this)" onBlur="NotActive(this)" /></td>
</tr>
<tr>
<td align="right"><span class="gen">Password:</span></td>
<td><input type="password" name="password" size="25" maxlength="25" class="post2" onFocus="Active(this)" onBlur="NotActive(this)" /></td>
</tr>
<tr align="center">
<td colspan="2"><span class="gen">Remember me: <input type="checkbox" name="autologin" /></span></td>
</tr>
<tr align="center">
<td colspan="2"><input type="hidden" name="redirect" value="" /><input type="submit" name="login" class="mainoption" value="Log in" /></td>
</tr>
<tr align="center">
<td colspan="2"><span class="gensmall">I forgot the password</span></td>
</tr>
</table>
Wget accept some parameters like --http-user=user --http-passwd=password, aside with proxies and certificate methods. Did you try one of these ?
How does the forum authentification works ?
Look at the construction of the login form within that page. If it's a typical POST form, retrieve the names of the elements which make up the form, and construct a wget query which will pass these in to the page that the form is submitted to
In this example, the form fields are called 'username' and 'password':
wget http://www.myforum.com/login.php --post-data="username=jeffrey&password=mypassword"
You will than have downloaded just the login page. With some configuration of other wget options, you should then be able to get it to traverse to the homepage and download this (especially if there is a link to it on the post login page). You may even get lucky and your forum automatically redirects you to the main page after login; in which case, wget will download this for you at that point (depending on the type of redirection issued by the server).