Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URL Variables 2

Status
Not open for further replies.

calista

Programmer
Jan 24, 2001
545
US
OK, same project, different question. The link below does not work. It passes the string of the variable name rather than the value of the variable (which is numeric). What's wrong with it? Probably something silly, but I sure don't see it. I have done this successfully on other pages passing alphanumeric data, but I've never tried numeric.

Code:
<a href=&quot;QuestionFormPage.cfm?first=#StartNextPage#&quot;>Next Question</a>
 
If it's not between <cfoutput> tags, the value won't get substituted (obvious I know) but double check this. Also, if the variable contains spaces, it will mess up the link for the browser. It's best to use urlencodedformat() around any variables you pass so that spaces and special characters get escaped. Try this.

<cfoutput>
<a href=&quot;QuestionFormPage.cfm?first=#urlencodedformat(StartNextPage)#&quot;>Next
Question</a>
</cfoutput>

Let me know if this fixes it,
GJ
 
Just a comment on what GunJack says about spaces in the URL variable --
Some versions of MSIE can handle the spaces, but they really mess up Netscape, it cannot deal with them at all, so it is very important to urlencodeformat them. Not just for Netscape, but it is a good practice.
:)
xor
 
Thanks, people! I knew I had done something ignorant. Thanks for the other advice, too. I'll keep that in mind. I'm new at this(just in case you hadn't figured that out already) :)
 
I am running into a similar problem, but slightly more convoluted...

The user needs to be able to upload documents into dynamically created subfolders. Thus the directory structure looks like:
/documents/#ClientName#/#ContractName#/#File.ClientFile#

The files are uploaded using CFFILE (which appears to be inserting _ for each <space>).

The directories are created using cfdirectory tags, checking first to see if they exist.

Should I be converting clientname, contractname, and filename into something URL friendly in the cfdirectory and cffile tags, or should the url that refers to the file merely be urlencodedformat(ClientName)... I have tried the latter with limited IE success but am not sure how to do the former if that is what is actually needed.
 
Anytime you pass dynamic values via url variables, you need to urlencode them unless you're certain they can never possibly contains spaces, ampersands, and other specials characters.

If you need to do this,
<cfoutput>
<a href=&quot;Page1.cfm?var1=/#ClientName#/#ContractName#/#File.ClientFile#&quot;></a>
</cfoutput>

Just wrap the urlencodedformat() function around the entire value like this and it handles all necessary escaping.
<cfoutput>
<a
href=&quot;Page1.cfm?var1=#urlencodedformat(&quot;/#ClientName#/#ContractName#/#File.ClientFile#&quot;)#&quot;>
</a>
</cfoutput>

Hope this helps,
GJ
 
Tried that:
<a href=&quot;../documents/#urlencodedformat(getNavBarClient.ClientName)#/#urlencodedformat(getContractInfo.ContractTitle)#/#Replace(FileName, &quot; &quot;, &quot;_&quot;, &quot;ALL&quot;)#&quot;><font size=&quot;-1&quot;>#FileName#</font></a>

Still not working.

 
Hey Prof,

I misunderstood what you were trying to do. I thought you needed to pass a path via a url variable. Try putting this in just before the link and post the results.

<cfoutput>
&quot;../documents/#urlencodedformat(getNavBarClient.ClientName)#/#urlencodedformat(getContractInfo.ContractTitle)#/#Replace(FileName,
&quot; &quot;, &quot;_&quot;, &quot;ALL&quot;)#/&quot;
</cfoutput>

This will show the actual link you're creating and should make it obvious if there is a problem in the url.

GJ
 
GJ,

Here is the output for an existing document for which I get a File Not Found error:

../documents/MJC%20Investment%20Company%20LLLP/MJC%20Limited%20/Carter_Draft-with_Shelly's_comments_hidden.doc

The folder names on the server are:
documents/MJC Investment Company LLLP/ MJC Limited /
The document does exist there.

Also, is cffile putting in the underscores in the filename, or is that part of the <input type=&quot;file> functionality?
 
Ok, I see the problem. I just checked the http 1.1 specs and spaces and escaped characters are not valid in the &quot;segment&quot; portion of a url. Each directory name between &quot;/&quot;s is considered a segment and these can only contain certain non-alphanumeric characters. You'll need to remove spaces and special characters before creating your directories. You can check rfc 2068 for a more detailed listing of what constitutes valid url characters.

As far as the underscores go, you can check #cffile.clientfile# to see the file name that was sent to cf. I don't know if cffile will do any type of renaming to handle spaces but I suspect browsers might even do this to avoid problems.

GJ
 
I think I just found the same answer but in a different way: the %20 at the end of the #contracttitle# indicates someone typed in the name with a space. However, when creating folders in Windows trailing spaces are ignored! Thus the folder #contracttitle# without the space exists but the url was calling #contracttitle #! In the db the space also existed (obviously); removing it solved the problem.

Guess I need to idiot-proof a little better.

Thanks once again for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top