• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

<cfif> problem

New Here ,
Jun 29, 2007 Jun 29, 2007

Copy link to clipboard

Copied

I'm trying to evalute whether a user is uploading an MS Word file with spaces in the filename. We cannot have spaces in filenames on our Internet site. So, basically, on the form page there is a field with a browse box for user to select their file.

It's is passed to the action page; here's the code.

I've used the same <cfif> statement on a bare bones page & it does work but for some reason it is not working on this page. I'm wondering if there's code on this page preventing it from being evaluted.





<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Human Resources Job Bank Form Action</title>
</head>

<body>


<!-- Check for spaces in filename -->

<cfif form.positionfile CONTAINS " ">

The document you attached to this position contains spaces in the filename. We cannot post documents containing spaces or special characters on the Internet.<br><br>

<b>How to fix the problem &#8212;</b><br><br>
<OL>
<LI>Please rename the original file without using spaces or punctuation. <br><br>The following characters are approved for file naming on the Web.

<ul type="square">
<li>Letters A-Z and a-z
<li>Numerals 0-9
<li>Dashes ( - )
<li>Underscores ( _ )
</ul>
<br>

<LI>Use your web browser's <b>Back</b> button to return to <b>Post a Position in the Job Bank</b> and reattach the position using the "Upload Document" box.<br><br>
<LI>Resubmit the position using a compatible filename. <BR><BR>

</OL><BR>

<cfelse>


<!--- capture the autonumber position id for use in the uploads table --->

<cflock name="#CreateUUID()#" timeout="20">
<cftransaction>

<!--- Insert the position info into the main positions table --->

<CFQUERY NAME="Insertposition" DATASOURCE="#Application.DSN#">
Insert into positions
(title, medcenterID, otherlocation, areaID, carelineID, grade, emailID, opendate, closedate)

VALUES

('#FORM.title#','#FORM.medcenterid#','#FORM.otherlocation#','#FORM.areaID#','#FORM.carelineid#','#FORM.grade#','#FORM.emailID#','#FORM.opendate#','#FORM.closedate#')
</CFQUERY>

<cfquery DATASOURCE="#Application.DSN#" name="getLastID">
SELECT MAX(positionID) as lastID
FROM positions
</cfquery>

</cftransaction>
</cflock>

<!--- Confirm to the user that the position was successfully added, allow them to add another or see the master list --->

<cfoutput>#DateFormat(createodbcdate(Now()),'mm/dd/yyyy')#
<br>
Position ID #getlastid.lastid#: #Form.Title#</cfoutput> has been added to the HR Job Bank.<br><br>

<!--- upload the file to the directory and only accept word docs --->


<cffile action="UPLOAD" filefield="positionfile" destination="#application.uploaddirectory#" nameconflict="MAKEUNIQUE">

<!--- Fill in the uploads table with the name and path for the uploaded file --->

<CFQUERY NAME="CreateDocumentRecord" DATASOURCE="#Application.DSN#">
INSERT INTO Uploads (positionID, Date_Published, File_Name, Upload_Path)
VALUES ('#VAL(getlastid.lastid)#',#createodbcdate(Now())#,'#FILE.ClientFile#','#FILE.ServerFile#')
</CFQUERY>

</cfif>
<!--- Grab Medical Center Name --->

<CFQUERY name="getmedicalcenter" DATASOURCE="#Application.DSN#">
SELECT medcenterID, medcenter_name
FROM location
WHERE medcenterID = #form.medcenterID#
</CFQUERY>

<!--- Grab Area Name --->
<CFQUERY name="getarea" DATASOURCE="#Application.DSN#">
SELECT areaID, area_name
FROM areaofconsideration
WHERE areaID = #form.areaID#
</CFQUERY>

<!--- Grab Care Line Name--->

<CFQUERY name="getcareline" DATASOURCE="#Application.DSN#">
SELECT carelineID, careline_name
FROM carelines
WHERE carelineID = #form.carelineID#
</CFQUERY>


</cfif>

</body>
</html>


TOPICS
Advanced techniques

Views

858

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 29, 2007 Jun 29, 2007

Copy link to clipboard

Copied

Right after your <body> tag, place the following:
<CFDUMP VAR=#form#>
Go to your form page and select a file that has a space in the name and click submit. What is the value of position file?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 29, 2007 Jun 29, 2007

Copy link to clipboard

Copied

1 thing to check is that in the form thats posting to this code has enctype="multipart/form-data"
I know its an obvious one but if you say this code works elsewhere, its a possibility.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 29, 2007 Jun 29, 2007

Copy link to clipboard

Copied

this is the value of the position file: C:\CFusionMX\runtime\servers\default\SERVER-INF\temp\wwwroot-tmp\neotmp60258.tmp

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 29, 2007 Jun 29, 2007

Copy link to clipboard

Copied

The form page has sent you a temporary filename that does not contain the space - therefore, it passes the CFIF test. A workaround would be to do a CFDIRECTORY ACTION="list" to obtain the filename of the most recent timestamp and do a CFFILE ACTION="rename" if you find a space in the filename.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 29, 2007 Jun 29, 2007

Copy link to clipboard

Copied

Thank you, that is a great suggestion, however we are not allowed to use <cfdirectory> tag.
If you have another suggestion not using <cfdirectory> I'm all ears!!

At least I know why it' s passing the validation now.

Thank you for your assistance

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 29, 2007 Jun 29, 2007

Copy link to clipboard

Copied

The form that's posting does have enctype="multipart/form-data".

Thank you for the response & assistance.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 29, 2007 Jun 29, 2007

Copy link to clipboard

Copied

Consider using the JavaScript onsubmit event. This would call a JavaScript function to search for a space in the filename.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 29, 2007 Jun 29, 2007

Copy link to clipboard

Copied

> We cannot have spaces in filenames on our Internet site.

Why not?

This is not a confrontational question; the answer might be relevant to the
solution.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 05, 2007 Jul 05, 2007

Copy link to clipboard

Copied

LATEST
Our organization's Internet site is hosted elsewhere and those are their guidelines. No spaces or special characters in filenames.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 01, 2007 Jul 01, 2007

Copy link to clipboard

Copied

Why not just rename the file after you upload it? You can strip out the spaces or replace them with underscores. Seems simpler than forcing the user to resubmit.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation