?
Solved

Need help with syntax for contstructing a URL to use in <cflocation> tag

Posted on 2006-06-01
26
Medium Priority
?
304 Views
Last Modified: 2013-12-24
I have this code:
<cfset urlString="modify" & #FORM.Choice# & ".cfm?recID=#URL.recID#")>
<cflocation url="test.cfm?urlstring=#urlString#">

When I execute it, my "test.cfm" page shows that the urlstring is
modifyingredients.cfm?recID=5.

YET, when I do this:
<cfset urlString="modify" & #FORM.Choice# & ".cfm?recID=#URL.recID#")>
<cflocation url=urlString>

the <cflocation> tag is trying to take me to modify.cfm.
It's obviously cutting off at the first &, which leads me to believe that I need some escape char or function to prevent it from  doing that, but I've been unable to figure out what I need to do (I'm fairly new to ColdFusion). I thought XMLFormat was the ticket but it isn't. Also tried URLEncodedFormat but that didn't help either. Same result.
0
Comment
Question by:alicia1234
  • 17
  • 4
  • 2
  • +2
26 Comments
 
LVL 7

Expert Comment

by:bwasyliuk
ID: 16811366
Can you try it this way:

<cfset urlString="modify" & FORM.Choice & ".cfm?recID=" & URL.recID>

Let me know if that changes anything
0
 

Author Comment

by:alicia1234
ID: 16811393
Thanks. You're asking me to just remove the # signs. I thought I had already tried that but just to be sure, I tried it again. It gives the same result ... the <cflocation> tag is trying to go to modify.cfm.
0
 

Author Comment

by:alicia1234
ID: 16811400
It's definitely that first & that is screwing it up (at least I think so!).
0
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 
LVL 7

Expert Comment

by:bwasyliuk
ID: 16811413
if it is going to Modify.cfm, then Form.choice must be equal to "".

Have you tried doing a <cfdump var="#form#"> before the cflocation?
0
 

Author Comment

by:alicia1234
ID: 16811437
But I know that FORM.choice isn't blank because of the test I did, right? (See my first-posted comment above.)
0
 

Author Comment

by:alicia1234
ID: 16811471
I don't know how <cfdump> works ... where does it dump the info to? I have debugging enabled but when I put the tag into my code, the info doesn't seem to show up anywhere. I looked in Help but it was no help. ;-(
0
 

Author Comment

by:alicia1234
ID: 16811539
I looked at the debugging info that I do have, and it does, indeed, look like the cflocation tag is trying to go to modify.cfm AND that the URL var recID is being passes successfully. So your thought that FORM.Choice must be blank could be correct, but why then would my test work?
0
 
LVL 9

Expert Comment

by:73Spyder
ID: 16811540
<cfset urlString="modify#FORM.Choice#.cfm?recID=#URL.recID#")>

This should also work.

0
 
LVL 7

Expert Comment

by:bwasyliuk
ID: 16811542
I've tried this with some basic options - and the

<cfset variables.choice="choice1">
<cfset url.recid=1>
<cfset urlString="modify" & variables.Choice & ".cfm?recID=" & URL.recID>

<cfoutput>#urlString#</cfoutput>


The output is "modifychoice1.cfm?recID=1" which is expected.  Have you tried feeding a dummy variable into the expression like I have done above?

Also the string:
<cfset urlString="modify" & #FORM.Choice# & ".cfm?recID=#URL.recID#")>
is not valid because of the ) on the end.
0
 
LVL 9

Expert Comment

by:73Spyder
ID: 16811545
CFDUMP should be displaying the info right on the screen probabbly near the top of the screen
0
 

Author Comment

by:alicia1234
ID: 16811652
I realized that the problem is something else entirely ... it's a long story but I realized that I do HAVE a page named modify.cfm ... it's not even getting to the <cflocation> tag ... my page is just executing the action of the form, which is to go to "modify.cfm" (which then has the code in it to process the form if it was submitted) ...
BUT here's what's weird...
the error I am getting is the classic HTTP 404 file not found error ...
it's trying to find:
http://localhost:8500/CookingWithAlicia/admin/modifyrecipe/modify.cfm
Yet when I enter that URL into a fresh browser window, the page comes up just fine ...
I should mention that "modify.cfm" was previously in the folder "admin", but then I added the folder "modifyrecipe" below admin and moved it there. I did all the renaming and moving within Dreamweaver and I answered yes to all questions about updating links. Maybe something bad is cached somewhere? I tried closing out of DW and coming back in but that didn't help.
What the heck is going on? I'm SOOO confused!!!!  ;-(
0
 

Author Comment

by:alicia1234
ID: 16811664
>>> Also the string:
>>> <cfset urlString="modify" & #FORM.Choice# & ".cfm?recID=#URL.recID#")>
>>> is not valid because of the ) on the end.
I know ... it was an error in transcription to my post here ;-)
0
 

Author Comment

by:alicia1234
ID: 16811777
So to simplify it a bit, here is the current problem:
When I execute my page, I get the HTTP 404 error. In the browser address window there is this:
http://localhost:8500/CookingWithAlicia/admin/modifyrecipe/modify.cfm
I move my cursor to the end of the address and hit enter, and the page comes up just fine.
I had recently moved the page modify.cfm into the new subdirectory "modifyrecipe" under "admin", but the moving was all done in Dreamweaver and I did update links automatically.
I shut down and restarted my pc, hoping to clear a cache problem, but I still have the same problem.

The modify.cfm page has a form with radio buttons. You select one and hit "ok" and the form gets submitted. The form action is to revisit the same page. There is code to determine if the form has been submitted, and if it has it then executes some other code. But now I'm not even getting to that code.
0
 
LVL 10

Expert Comment

by:rob_lorentz
ID: 16811820
right before the cflocation. try a cfDump and cfabort. that what you can see what form variables are defined and what they contain......also you can simplify the cfset for urlString....

<cfset urlString="modify#FORM.Choice#.cfm?recID=#URL.recID#">
<cfdump var="#form#">
<cfabort>
<cflocation url="test.cfm?urlstring=#urlString#">
0
 

Author Comment

by:alicia1234
ID: 16811837
I recreated the page from scratch.
In so doing, I've isolated it to this:

If this code is at the beginning of my page, then when I click on the "GO" button of my form (which means that this code is supposed to get executed), then I get the HTTP 404 error):
<cfparam name="URL.RecID" default="5">

<!--- Construct the URL for the page to go to if a selection was made --->
<cfif IsDefined("FORM.CWA_Modify") AND FORM.CWA_Modify eq "formModify">
<cfset urlString=URLEncodedFormat("modify" & #FORM.Choice# & ".cfm?recID=#URL.recID#")>
      <cflocation url=urlString>
<!--- <cflocation url="test.cfm?urlstring=#urlString#"> --->

</cfif>

<cfquery name="rs_Recipe" datasource="connCWArecipes">
SELECT *
FROM tblRecipes
WHERE RecipeID=#URL.recID#
</cfquery>

If that code is NOT there, clicking on "GO" brings me back in to the page without error.
SO I'm still very confused.
0
 

Author Comment

by:alicia1234
ID: 16811847
When I execute the page without the code (as explained in previous post) and use the debugger, I CAN SEE that "Choice" has been correctly set to "ingredients".
So FORM.Choice is defined.
I'm upping the points on this ...
0
 

Author Comment

by:alicia1234
ID: 16811881
Now I've isolated it to just this one line of code:

      <cflocation url=urlString>

If that line is in there, I get the HTTP 404 error; if it isn't, I get back into the page with FORM.Choices correctly set.
So I've come full circle ... the problem seems to be the urlString decoding ??

0
 

Author Comment

by:alicia1234
ID: 16811891
NOTE: this works (though it isn't what I want to do):

<cflocation url="modify.cfm">
0
 

Author Comment

by:alicia1234
ID: 16811911
OK it works now ... God only knows why it didn't before.
Here's the code that works ... so simple, really!

<cfif IsDefined("FORM.CWA_Modify") AND FORM.CWA_Modify eq "formModify">
<cfset urlString="modify" & #FORM.Choice# & ".cfm?recID=#URL.recID#">
      <cflocation url=#urlString#>
</cfif>

So from my originally-posted question, the only thing that was required was to put # signs around the "urlString" in the <cflocation> tag.
0
 

Author Comment

by:alicia1234
ID: 16811959
I think this now qualifies for an "I solved it myself" but if any of you disagree please let me know. I did read through all of the posts and none of them (I think!) had the correct answer.
Thanks.
0
 
LVL 7

Expert Comment

by:bwasyliuk
ID: 16811984
Glad to hear you got it working.
0
 

Author Comment

by:alicia1234
ID: 16812015
I do have another open question that maybe one of you can help with  ;-)

http://www.experts-exchange.com/Web/WebDevSoftware/DreamWeaver/Q_21871516.html
0
 
LVL 18

Accepted Solution

by:
Plucka earned 2000 total points
ID: 16815503
Ok,

It's good that it's working, but your code is bad, your mixing styles and inappropiatly using #'s

Change

<cfset urlString="modify" & #FORM.Choice# & ".cfm?recID=#URL.recID#">
<cflocation url=#urlString#>

to

<cfset urlString="modify" & FORM.Choice & ".cfm?recID=" & URL.recID>
<cflocation url="#urlString#">

Note, both lines are different
0
 

Author Comment

by:alicia1234
ID: 16816171
Plucka: thanks. Your suggested code does work. If you could explain to my in more detail why mine was "bad", I'll give you the points. I am still learning and would really like to understand "why" things are coded the way they are, not just "what" the code should be. Thanks! ;-)
0
 
LVL 18

Expert Comment

by:Plucka
ID: 16820992
Alicia,

Sure.

1. You don't need to use #'s around variables unless they are embeded in other tags or another string thus & #Form.Choice# should just be & Form.Choice
2. You were using a mixture of appending strings using & and embedding variables in strings, thus recId=#URL.recID# was changed, now both are valid methods but you were using both of them on one line you should have had one or the other, here are both complete options, see which you prefer

a: <cfset urlString="modify#FORM.Choice#.cfm?recID=#URL.recID#" />
b: <cfset urlString="modify" & FORM.Choice & ".cfm?recID=" & URL.recID />

FYI, from what i've seen most people do a as it's more natural to a CF developer

3. Your <cflocation should have the paramater enclosed in quotes, as it's possible to have a URL with spaces which would break your method. Also XHTML standard is to put all attributes in quotes.

A lot of new developers get confused with #'s i've seen it a lot they do things like

<cfset #x# = 3 />
<cfset #y# = 5 />
<cfset #z# = #X# * #y# />

Now CF is very forgiving and works a lot of stuf out but this really should be

<cfset x=3 />
<cfset y=5 />
<cfset z=x*y />

Also, note I close all the tags using /> this is another XHTML standard and also an XML standard, not enforced by Coldfusion yet, but probably will be at some point so good pratice.

0
 

Author Comment

by:alicia1234
ID: 16821579
Thanks!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

839 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