SiriusPhil
asked on
Pass a URL as a variable in the URL
Is it possible to pass a URL as a variable in the URL? If so, how would I do it?
Phil Hayes
Phil Hayes
yeah it's possible
Like this
startpage.cfm
----------------------
<cfset MyVarr = "Http://www.yourdomain.cfm">
<form name="myform" action="actionpage.cfm?Var iableOne=# MyVarr#" method="post">
...form elements...
...submit button....
</form>
actionpage.cfm
-------------------------- ---------- ------
<cfparam name="url.VariableOne" default="">
<cfoutput>
My URL Variable: #Url.VariableOne#<br>
<a href="#Url.VariableOne#"> Here's the link</a>
</cfoutput>
Like this
startpage.cfm
----------------------
<cfset MyVarr = "Http://www.yourdomain.cfm">
<form name="myform" action="actionpage.cfm?Var
...form elements...
...submit button....
</form>
actionpage.cfm
--------------------------
<cfparam name="url.VariableOne" default="">
<cfoutput>
My URL Variable: #Url.VariableOne#<br>
<a href="#Url.VariableOne#"> Here's the link</a>
</cfoutput>
URLEncodedFormat(string [, charset ])
oops forgot to account for the URLEncodedFormat
here:
startpage.cfm
----------------------
<cfset MyVarr = "http://www.yourdomain.cfm">
<form name="myform" action="actionpage.cfm?Var iableOne=# URLEncoded Format(MyV arr)#" method="post">
...form elements...
...submit button....
</form>
actionpage.cfm
-------------------------- ---------- ------
<cfparam name="URL.VariableOne" default="">
<cfset MyVarr = URLDecode(URL.VariableOne) >
<cfoutput>
My URL Variable: #MyVarr#<br>
<a href="#MyVarr#"> Here's the link</a>
</cfoutput>
there ya go ;o)
~trail
oops forgot to account for the URLEncodedFormat
here:
startpage.cfm
----------------------
<cfset MyVarr = "http://www.yourdomain.cfm">
<form name="myform" action="actionpage.cfm?Var
...form elements...
...submit button....
</form>
actionpage.cfm
--------------------------
<cfparam name="URL.VariableOne" default="">
<cfset MyVarr = URLDecode(URL.VariableOne)
<cfoutput>
My URL Variable: #MyVarr#<br>
<a href="#MyVarr#"> Here's the link</a>
</cfoutput>
there ya go ;o)
~trail
ASKER
Woops..
Forgot to tell you one thing...
Some of the URL's I want to send as variables have variables in them too.
Can I send somethong like...
http://foo.com?id=1
through a URL variable?
Forgot to tell you one thing...
Some of the URL's I want to send as variables have variables in them too.
Can I send somethong like...
http://foo.com?id=1
through a URL variable?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
here:
startpage.cfm
----------------------
<cfset next = SomethingElse">
<cfset mysecond = "Something">
<cfset MyVarr = "http://www.yourdomain.cfm?mySecond=#SecondVarr#&next=#next#">
<cfset extra = "AdditionalVariables">
<form name="myform" action="actionpage.cfm?MyU RL=#URLEnc odedFormat (MyVarr)#& extra=#ext ra#" method="post">
...form elements...
...submit button....
</form>
actionpage.cfm
-------------------------- ---------- ------
<cfparam name="URL.MyURL" default="">
<cfset MyVarr = URLDecode(URL.MyURL)>
<cfparam name="URL.extra" default="">
<cfset extra = URL.extra>
<cfoutput>
My URL Variable: #MyVarr#<br>
My Extra Variables: #extra#<br>
<a href="#MyVarr#"> Here's the link</a>
</cfoutput>
startpage.cfm
----------------------
<cfset next = SomethingElse">
<cfset mysecond = "Something">
<cfset MyVarr = "http://www.yourdomain.cfm?mySecond=#SecondVarr#&next=#next#">
<cfset extra = "AdditionalVariables">
<form name="myform" action="actionpage.cfm?MyU
...form elements...
...submit button....
</form>
actionpage.cfm
--------------------------
<cfparam name="URL.MyURL" default="">
<cfset MyVarr = URLDecode(URL.MyURL)>
<cfparam name="URL.extra" default="">
<cfset extra = URL.extra>
<cfoutput>
My URL Variable: #MyVarr#<br>
My Extra Variables: #extra#<br>
<a href="#MyVarr#"> Here's the link</a>
</cfoutput>
yeah good catch mrichmon, pass any additional url variables before the passedURL
also you make a good point about accessing variables in the passed url.
between the two posts that should cover what you are looking to do ;o)
~trail
also you make a good point about accessing variables in the passed url.
between the two posts that should cover what you are looking to do ;o)
~trail
What do you mean? Like:
http://www.example.com/url.php?url=http://someotherexample.com/
? Yes, that's possible and you would get it out of the URL just like any other GET variable. I have no idea about ColdFusion syntax but it would be like that. Just make sure to URLEncode the URL first.
Regards,
Zyloch