[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 813
  • Last Modified:

coldfusion UrlEncodedFormat problem

Hello experts.
I'm trying to use the following code to get url values:
<cfoutput>#urlencodedformat(ErrorMessage,UTF-8)#</cfoutput>
but i get the error message:
Variable UTF is undefined.

Any help?
0
Panos
Asked:
Panos
  • 11
  • 8
1 Solution
 
Brijesh ChauhanStaff IT EngineerCommented:
That is because anything between # # is considered as a variable, why do you have UTF-8 in there ?

<cfoutput>#urlencodedformat(ErrorMessage)#</cfoutput> - This should work...
0
 
PanosAuthor Commented:
Hi.
I get this using urlencodedformat
%2D%3E%20%3C%21%2D%2D%2D%20Please%20enter%20a%20last%20name%20for%20the%20billing%20address%20%2D%2D%2D%3E%EF%BF%BD%C5%BC%3B%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%C4%B5%20%C4%BF%20%22%EF%BF%BD%2F%EF%BF%BD%EF%BF%BD%C4%BF%22%20%EF%BF%BD%C4%B1%20%EF%BF%BD%C4%BF%EF%BF%BD%C7%B5%EF%BF%BD%EF%BF%BD%20%EF%BF%BDm%EF%BF%BD%C3%B7%EF%BF%BD%3Cbr%3E%2D%3E%20%3C%21%2D%2D%2D%20Please%20enter%20a%20first%20name%20for%20the%20billing%20address%20%2D%2D%2D%3E%EF%BF%BD%C5%BC%3B%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%C4%B5%20%C4%BF%20%22%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%22%20%EF%BF%BD%C4%B1%20%EF%BF%BD%C4%BF%EF%BF%BD%C7%B5%EF%BF%BD%EF%BF%BD%20%EF%BF%BDm%EF%BF%BD%C3%B7%EF%BF%BD%3Cbr%3E%2D%3E%20%3C%21%2D%2D%2D%20Please%20enter%20a%20billing%20address%20%2D%2D%2D%3E%EF%BF%BD%C5%BC%3B%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%C4%B5%20%C4%B7%20%22%EF%BF%BD%EF%BF%BD%EF%BF%BD%CD%B8%C5%BD%C3%B7%22%20%EF%BF%BD%C4%B1%20%EF%BF%BD%C4%BF%EF%BF%BD%C7%B5%EF%BF%BD%EF%BF%BD%20%EF%BF%BDm%EF%BF%BD%C3%B7%EF%BF%BD%3Cbr%3E%2D%3E%20%3C%21%2D%2D%2D%20Please%20enter%20a%20city%20for%20the%20billing%20address%20%2D%2D%2D%3E%EF%BF%BD%C5%BC%3B%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%C4%B5%20%C4%B7%EF%BF%BD%20%22%EF%BF%BD%CC%BB%EF%BF%BD%22%20%EF%BF%BD%C4%B1%20%EF%BF%BD%C4%BF%EF%BF%BD%C7%B5%EF%BF%BD%EF%BF%BD%20%EF%BF%BDm%EF%BF%BD%C3%B7%EF%BF%BD%3Cbr%3E%2D%3E%20%3C%21%2D%2D.................
0
 
Brijesh ChauhanStaff IT EngineerCommented:
okay.. try this, put UTF-8 in quotes..

<cfoutput>#urlencodedformat(ErrorMessage,'UTF-8')#</cfoutput>
0
Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

 
Brijesh ChauhanStaff IT EngineerCommented:
example..


	 <cfset errorMessage = 'Hi I an Error'>
         
         <cfoutput>#URLEncodedFormat(ErrorMessage,'utf-8')#</cfoutput>

Open in new window

0
 
PanosAuthor Commented:
The result is the same
(By the way,i copied a part of the url that has the same format:
ErrorMessage=-%3E%20%3C!---%20Please%20enter%20a%20last%20name%20for%20the%20billing%20address%20---%3E%A3%C5%BC%C0%BB%B7%C1%CE%...........)
0
 
Brijesh ChauhanStaff IT EngineerCommented:
if you want to read the result, then use URLDECODE

 #URLDecode(ErrorMessage)#
0
 
Brijesh ChauhanStaff IT EngineerCommented:
example...

		 <cfset errorMessage = '%3E%20%3C%20Please%20enter%20a%20last%20name%20for%20the%20billing%20address%20%3E'>
         
         <cfoutput>#URLDecode(errorMessage,'utf-8')#</cfoutput>

Open in new window


this will output

< Please enter a last name for the billing address > 
0
 
PanosAuthor Commented:
This is the result:
¿z;¿¿¿¿j ¿ "¿/¿¿¿" ¿i ¿¿¿¿¿¿ ¿m¿÷¿
-> ¿z;¿¿¿¿j ¿ "¿¿¿¿¿" ¿i ¿¿¿¿¿¿ ¿m¿÷¿
-> ¿z;¿¿¿¿j k "¿¿¿¿Ž÷" ¿i ¿¿¿¿¿¿ ¿m¿÷¿
-> ¿z;¿¿¿¿j k¿ "¿¿¿" ¿i ¿¿¿¿¿¿ ¿m¿÷¿
-> ¿9¿¿¿j k¿ "¿¿y¿u¿¿" ¿i ¿¿¿¿¿¿ ¿m¿÷¿
-> ¿9¿¿¿j ¿ "¿¿¿¿" ¿i ¿¿¿¿¿¿ ¿m¿÷¿
-> ¿¿q¿¿¿¿ ¿z;¿¿¿¿j ¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿¿¿.
-> ¿9¿¿¿¿¿¿¿j ¿¿ ¿¿¿¿¿ ¿¿¿¿¿¿¿¿.
-> ¿¿q¿¿¿¿ ¿z;¿¿¿¿j ¿ email ñ¿.
-> ¿m5¿ ¿¿ ¿z¿¿¿õj ¿¿ ¿¿¿ ¿¿¿ ¿¿¿ L¿ ¿¿?¿¿õ¿¿.

I'm using greek language
0
 
PanosAuthor Commented:
Take a look tothe following image please for the output
screen.gif
0
 
Brijesh ChauhanStaff IT EngineerCommented:
what is the charset you use for greek language ? use the same one in URLDecode instead of utf-8
0
 
Brijesh ChauhanStaff IT EngineerCommented:
Take a look here

http://a4esl.org/c/charset.html

the charset for greek language it says is iso-8859-7, what happens if you use it

<cfoutput>#URLDecode(errorMessage,'iso-8859-7')#</cfoutput>
0
 
PanosAuthor Commented:
The charset i'm using is utf-8:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

The problem appears when i'm catching errors from a server side form validation and try to send all these back to the form page to show the errors.

<cfset URLString = '?action=checkout'>

<CFLOOP COLLECTION="#Form#" ITEM="VarName">
  <cfset URLString = '#URLString#&#VarName#=#evaluate(varname)#'>
</CFLOOP>


<!--- validation code--->

<cfif Len(ship_lastname) IS 0>
        <cfset TotalErrors = TotalErrors + 1>
        <cfset ErrorList = ListAppend(ErrorList,'ship_lastname')>
        <cfset ErrorMessage = ErrorMessage & '-> .....greek text .....<br>'>
    </cfif>
<!--- end vaidation--->
<cfset URLString = URLString & '&ErrorMessage=#ErrorMessage#&TotalErrors=#TotalErrors#&ErrorList=#ErrorList#'>

<cfif TotalErrors GT 0>
      <cflocation URL = "index.cfm#URLString#" addtoken="no">
</cfif>
0
 
PanosAuthor Commented:
the result is the same for iso-8859-7
0
 
Brijesh ChauhanStaff IT EngineerCommented:
before CFLOCATION have the URLString converted to URLENCODED Format

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

The problem appears when i'm catching errors from a server side form validation and try to send all these back to the form page to show the errors.

<cfset URLString = '?action=checkout'>

<CFLOOP COLLECTION="#Form#" ITEM="VarName">
  <cfset URLString = '#URLString#&#VarName#=#evaluate(varname)#'>
</CFLOOP>


<!--- validation code--->

<cfif Len(ship_lastname) IS 0>
        <cfset TotalErrors = TotalErrors + 1>
        <cfset ErrorList = ListAppend(ErrorList,'ship_lastname')>
        <cfset ErrorMessage = ErrorMessage & '-> .....greek text .....<br>'>
    </cfif>
<!--- end vaidation--->
<cfset URLString = URLString & '&ErrorMessage=#ErrorMessage#&TotalErrors=#TotalErrors#&ErrorList=#ErrorList#'>

<cfset URLString = urlEncodedFormat(URLString,'utf-8') />

<cfif TotalErrors GT 0>
      <cflocation URL = "index.cfm?#URLString#" addtoken="no">
</cfif>


Then while reading back.. (in your index.cfm)

use <cfoutput>#URLDecode(URLString,'utf-8')#</cfoutput>
0
 
gdemariaCommented:
> The result is the same
(By the way,i copied a part of the url that has the same format:
ErrorMessage=-%3E%20%3C!---%20Please%20enter%20a%20last%20name%20for%20the%20billing%20address%20---%3E%A3%C5%BC%C0%BB%B7%C1%CE%...........)

@panosms, what result are you expecting?  what result do you want that is different from what you are getting?   The function seems to be doing it's job correctly but you are saying it's not what you want/need.    Please explain the problem you are having.

0
 
PanosAuthor Commented:
The problem i have now is that i have in my index page all my  cficlude depending the url action.

encoding all the urlstring i'm encoding the action too and so i get an error 404 page not found.
can i make any exception for action?
0
 
PanosAuthor Commented:
Hi gdemaria

I need the greek text and not something like the screen i posted above
0
 
PanosAuthor Commented:
OK.
I'm very close to  the solution.
I followed the instruction from export brijeshchauhan with a little change.
I did not use the line <cfset URLString = '?action=checkout'> and instead of that i did change the cflocation to:
<cflocation URL = "index.cfm?action=checkout&#URLString#" addtoken="no">

Now i have it all encoded in the url.
To decode all i need from the  url i use now:
<cfset urlstring = '#urldecode(query_string,'utf-8')# '>

What is missing is now to get :
Totalerrors   (<cfif isdefined('url.TotalErrors')>..........)
ErrorList
ErrorMessage

Any help?

0
 
PanosAuthor Commented:
I have a solution now.
Please check if it could be simplier than that.
On the validation page:
<cfset URLStringErrormessage = urlEncodedFormat(ErrorMessage,'utf-8')>
<cfset URLStringTotalErrors = urlEncodedFormat(TotalErrors,'utf-8')>
<cfset URLStringErrorList = urlEncodedFormat(ErrorList,'utf-8')>
<cfif TotalErrors GT 0>
      <cflocation URL = "index.cfm?action=checkout&ErrorMessage=#URLStringErrormessage#&TotalErrors=#URLStringTotalErrors#&ErrorList=#URLStringErrorList#" addtoken="no">
</cfif>

and on the index page of course:
<cfoutput>#URLDecode(errorMessage,'utf-8')#</cfoutput>
0
 
PanosAuthor Commented:
Thank you for your help
regards
panos
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 11
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now