We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

coldfusion UrlEncodedFormat problem

Panos
Panos asked
on
Medium Priority
896 Views
Last Modified: 2012-05-11
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?
Comment
Watch Question

Brijesh ChauhanStaff IT Engineer

Commented:
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...

Author

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.................
Brijesh ChauhanStaff IT Engineer

Commented:
okay.. try this, put UTF-8 in quotes..

<cfoutput>#urlencodedformat(ErrorMessage,'UTF-8')#</cfoutput>
Brijesh ChauhanStaff IT Engineer

Commented:
example..


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

Open in new window

Author

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%...........)
Brijesh ChauhanStaff IT Engineer

Commented:
if you want to read the result, then use URLDECODE

 #URLDecode(ErrorMessage)#
Brijesh ChauhanStaff IT Engineer

Commented:
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 > 

Author

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

Author

Commented:
Take a look tothe following image please for the output
screen.gif
Brijesh ChauhanStaff IT Engineer

Commented:
what is the charset you use for greek language ? use the same one in URLDecode instead of utf-8
Brijesh ChauhanStaff IT Engineer

Commented:
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>

Author

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>

Author

Commented:
the result is the same for iso-8859-7
Staff IT Engineer
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

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%...........)

@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.

Author

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?

Author

Commented:
Hi gdemaria

I need the greek text and not something like the screen i posted above

Author

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?

Author

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>

Author

Commented:
Thank you for your help
regards
panos
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.