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

URLEncodedFormat() / URLDecode

LEGEND ,
Jul 11, 2006 Jul 11, 2006

Copy link to clipboard

Copied

I found the live docs version of these 2 functions, but does anyone know a
place to find a easier explanation on how to use these?

I know to use the URLEncodedFormat() you would use:
<cflocation url="page.cfm?var=#URLEncodedFormat('Form.variabletosend#')">

But I am not sure how to 'decode' it on another page to use it as a variable
on another page.

Thanks
--
Wally Kolcz
Developer / Support


TOPICS
Advanced techniques

Views

1.8K

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
Enthusiast ,
Jul 11, 2006 Jul 11, 2006

Copy link to clipboard

Copied

It's probably just a typo but the closing # needs to be on the other side of the bracket.

You use URLDecode the same way

<cfset myvar = URLDecode(url.var)>

Ken

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 ,
Jul 12, 2006 Jul 12, 2006

Copy link to clipboard

Copied

yeah, I forgot the #. Thanks for the info. Going to try it now!


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
Participant ,
Jul 12, 2006 Jul 12, 2006

Copy link to clipboard

Copied

If you access the variable, as a normal CF variable:

<cfset newVar=var>
or
<cfset newVar=URL.var>

You do not need to do anything, because CF will perform necessary conversion for you.

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 ,
Jul 12, 2006 Jul 12, 2006

Copy link to clipboard

Copied

Now if I were to attempt to pass 3 variables across a URL, would I have to
encode each of them separately?

<cflocation
url="payment.cfm?username=#FORM.username#&email=#FORM.email#&memtype=#FORM.memtype#">


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
Enthusiast ,
Jul 12, 2006 Jul 12, 2006

Copy link to clipboard

Copied

While you more than likely can do this in one urlencode function, I'm a bit wierd and like to see exactly what's happening in the code by looking at it. So I would do them seperately.

Mr Black
This is why I would also use urldecode, just makes it obvious what's happening.

Ken

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 ,
Jul 12, 2006 Jul 12, 2006

Copy link to clipboard

Copied

That's cool. I think I would rather do it individually.

What is the best (person preferences) charset format for encoding?


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
Participant ,
Jul 13, 2006 Jul 13, 2006

Copy link to clipboard

Copied

LATEST
1. You need to use URLEncodedFormat() for every value you pass, not for the entire query string.

2. You cannot arbitrary apply URLDecode() in your application, if you receive values, as Cold Fusion variables.
Consider the following example:

<cfset mvar="C/C++">
<a href="test.cfm?mvar=<cfoutput>#URLEncodedFormat(mvar)#<cfoutput>">Click Me</a>

Then, on test.cfm page:

<cfoutput>
#mvar# #URLDecode(mvar)#
</cfoutput>

You will see that values are different and the second one is not that you passed....

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