removing %20's

managing variables in URLs

Page 1 of 1

9 Replies - 5977 Views - Last Post: 16 December 2010 - 01:50 PM Rate Topic: -----

#1 scottb50   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-December 10

removing %20's

Posted 14 December 2010 - 08:41 PM

I am receiving a returned URL that looks something like this:

" myDomanin.com//gateway.cfm?custom%20first_nam=slam&custom%20las t_nam=mally "

The problem is that I need to get the first_nam variable to be "slam" and the last_nam variable to be "mally" (using the example above).

Unfortunately, I am presented with the URL structure that gives me custom%20first_nam=slam and custom%20last_nam=mally.

How would I work some CF magic so that I could strip the URL of the "custom%20" only ?

Many thanks in advance for you help with this.

This post has been edited by scottb50: 14 December 2010 - 08:42 PM


Is This A Good Question/Topic? 0
  • +

Replies To: removing %20's

#2 Craig328   User is offline

  • I make this look good
  • member icon

Reputation: 2024
  • View blog
  • Posts: 3,609
  • Joined: 13-January 08

Re: removing %20's

Posted 15 December 2010 - 06:36 AM

Welcome to D.I.C. Scott!

You could try the built in CF function URLDecode. That should take care of your %20's for you.
Was This Post Helpful? 0
  • +
  • -

#3 scottb50   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-December 10

Re: removing %20's

Posted 15 December 2010 - 12:35 PM

Thanks for the welcome. This place is great.

I looked into the URLdecode and gave this a shot:

<cfset newUrl = URLdecode("#URL#")>

As you might imagine, this made the CF gods very unhappy and I was told that "Complex object types cannot be converted to simple values." Is there a way that I can use this URLdecode function to just strip out those pesky %20's? the example in the CF documentation is in the form of a <cfscript>. I'm not advanced enough *sigh* to script like that - which is why I LOVE CF.

Can you point me in the direction of an example that isn't in the <CFSCRIPT> format? I'm not looking for you to do my homework for me!

Many thanks!



View PostCraig328, on 15 December 2010 - 05:36 AM, said:

Welcome to D.I.C. Scott!

You could try the built in CF function URLDecode. That should take care of your %20's for you.

Was This Post Helpful? 0
  • +
  • -

#4 Craig328   User is offline

  • I make this look good
  • member icon

Reputation: 2024
  • View blog
  • Posts: 3,609
  • Joined: 13-January 08

Re: removing %20's

Posted 15 December 2010 - 12:42 PM

Instead of this:
<cfset newUrl = URLdecode("#URL#")>

Try this:
<cfset newUrl = URLdecode(URL)>


As a general rule, you don't need to put pound signs on variables that you evaluate inside of functions. It doesn't usually generate an error but it's not necessary (in most cases) and will add an extra cycle or two to the CF server as it evaluates it anyway.

That said, the error you're getting is because you're using a variable name that is also a scope. There is a URL scope and that is a structure (in CF) and cannot be evaluated with a function like this. Your solution (and this is a very good practice to get into) is to scope every variable you use so as to avoid this problem and others. Instead of referring to the variable as "url", refer to it with it's preceding scope like variables.url or session.url or client.url or whatever is appropriate.

This post has been edited by Craig328: 15 December 2010 - 12:47 PM

Was This Post Helpful? 0
  • +
  • -

#5 scottb50   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-December 10

Re: removing %20's

Posted 15 December 2010 - 02:00 PM

I had a feeling the #'s were going to be problematic. I tried the example you gave me <cfset newUrl = URLdecode(URL)> and got the same error. I tried to session.URL in place of just URL, but got a message saying that URL was not defined in the session scope, which makes sense. Since I don't have any control of the generation of the URL, is it still possible (and/or advisable) to scope this somehow?

I appreciate your patience.
Was This Post Helpful? 0
  • +
  • -

#6 Craig328   User is offline

  • I make this look good
  • member icon

Reputation: 2024
  • View blog
  • Posts: 3,609
  • Joined: 13-January 08

Re: removing %20's

Posted 15 December 2010 - 02:13 PM

View Postscottb50, on 15 December 2010 - 03:00 PM, said:

I had a feeling the #'s were going to be problematic. I tried the example you gave me <cfset newUrl = URLdecode(URL)> and got the same error. I tried to session.URL in place of just URL, but got a message saying that URL was not defined in the session scope, which makes sense. Since I don't have any control of the generation of the URL, is it still possible (and/or advisable) to scope this somehow?

I appreciate your patience.



Yep. It can be fixed. Do me a favor and post the code where you got the URL from. How you got URL to begin with, that is.
Was This Post Helpful? 0
  • +
  • -

#7 scottb50   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-December 10

Re: removing %20's

Posted 15 December 2010 - 03:19 PM

View PostCraig328, on 15 December 2010 - 01:13 PM, said:

View Postscottb50, on 15 December 2010 - 03:00 PM, said:

I had a feeling the #'s were going to be problematic. I tried the example you gave me <cfset newUrl = URLdecode(URL)> and got the same error. I tried to session.URL in place of just URL, but got a message saying that URL was not defined in the session scope, which makes sense. Since I don't have any control of the generation of the URL, is it still possible (and/or advisable) to scope this somehow?

I appreciate your patience.



Yep. It can be fixed. Do me a favor and post the code where you got the URL from. How you got URL to begin with, that is.



This code is generated by Aweber, which adds an entry to my account and returns the URL that is making me cry.
Here's the code for the form:
<!-- AWeber Web Form Generator 3.0 -->
<form method="post" class="af-form-wrapper" action="http://www.aweber.com/scripts/addlead.pl"  >
<div style="display: none;">
<input type="hidden" name="meta_web_form_id" value="588362046" />
<input type="hidden" name="meta_split_id" value="" />
<input type="hidden" name="listname" value="widgettest" />
<input type="hidden" name="redirect" value="http://freerollmadness.com/sandbox/gateway/gateway.cfm" id="redirect_4d62f039cc049acce90ac7177dd5b0d4" />
<input type="hidden" name="meta_redirect_onlist" value="http://freerollmadness.com/sandbox/gateway/already-entered.cfm" />
<input type="hidden" name="meta_adtracking" value="Widget_Test_Form" />
<input type="hidden" name="meta_message" value="1001" />
<input type="hidden" name="meta_required" value="custom first_nam,email" />
<input type="hidden" name="meta_forward_vars" value="1" />
<input type="hidden" name="meta_tooltip" value="" />
</div>
<div id="af-form-588362046" class="af-form"><div id="af-header-588362046" class="af-header"><div class="bodyText"><p>Step 1</p></div></div>
<div id="af-body-588362046" class="af-body af-standards">
<div class="af-element">
<label class="previewLabel" for="awf_field-14501317">First Name</label>
<div class="af-textWrap"><input type="text" id="awf_field-14501317" class="text" name="custom first_nam" value=''  tabindex="500" /></div>
<div class="af-clear"></div></div><div class="af-element">
<label class="previewLabel" for="awf_field-14501318">Last Name</label>
<div class="af-textWrap"><input type="text" id="awf_field-14501318" class="text" name="custom last_nam" value=''  tabindex="501" /></div>
<div class="af-clear"></div></div><div class="af-element">
<label class="previewLabel" for="awf_field-14501316">Email: </label>
<div class="af-textWrap"><input class="text" id="awf_field-14501316" type="text" name="email" value="" tabindex="502"  />
</div><div class="af-clear"></div>
</div>
<div class="af-element buttonContainer">
<input name="submit" class="submit" type="submit" value="Go To Step 2" tabindex="503" />
<div class="af-clear"></div>
</div>
</div>
</div>
<div style="display: none;"><img src="http://forms.aweber.com/form/displays.htm?id=rBwczGxMDCxs" alt="" /></div>
</form>

<!-- /AWeber Web Form Generator 3.0 -->



This then returns:
http://freerollmadness.com/sandbox/gateway/gateway.cfm?custom%20first_nam=smith&custom%20last_nam=smithee&email=lkhdk%40scotty.com&from=lkhdk%40scotty.com&listname=widgettest&meta_adtracking=widget_test_form&meta_message=1001&meta_required=custom%20first_nam,email&meta_split_id=&meta_tooltip=&meta_web_form_id=588362046&name=&submit=Go%20To%20Step%202


I have tried to remove the spaces from the input names, but that only returned an error from Aweber.

This post has been edited by Craig328: 16 December 2010 - 06:55 AM

Was This Post Helpful? 0
  • +
  • -

#8 scottb50   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-December 10

Re: removing %20's

Posted 15 December 2010 - 05:50 PM

To those who find this thread in the future, a perfect and elegant solution came in from BKBK -

<cfset lname = url["custom last_nam"]> 



Thank you all for your hard work and attention. I truly appreciate it.
Was This Post Helpful? 0
  • +
  • -

#9 Craig328   User is offline

  • I make this look good
  • member icon

Reputation: 2024
  • View blog
  • Posts: 3,609
  • Joined: 13-January 08

Re: removing %20's

Posted 16 December 2010 - 06:56 AM

Good to hear you got it fixed. Just for the record, who/what is BKBK?
Was This Post Helpful? 0
  • +
  • -

#10 scottb50   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-December 10

Re: removing %20's

Posted 16 December 2010 - 01:50 PM

View PostCraig328, on 16 December 2010 - 05:56 AM, said:

Good to hear you got it fixed. Just for the record, who/what is BKBK?


I'm not sure. I got an email in the middle of the night with the answer and a parable about ancient Egyptian bread, sand, and code (not kidding). I think he's Batman.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1