Although I doubt there would be speed benefit, but wouldn't it be a little
cleaner to just do it like this?
<cfif isdefined("cgi.query_string")>
<cfloop list="#cgi.query_string#" delimiters="&" index="valuepair">
<cfset urlname = "#ListGetAt(valuepair, 1, "=")#">
<cfif not isdefined('attributes.' & urlname)>
<cftry>
<cfset setvariable("caller.attributes.#urlname#" ,
"#evaluate("url."&"#urlname#")#")>
<cfset request.attributeslist =
listappend(request.attributeslist,urlname,"&")>
<cfset request.attributeslist =
listappend(request.attributeslist,urlencodedformat(evaluate("url.#urlname#")
),"=")>
<cfcatch>
<cfset setvariable("caller.attributes.#urlname#" , TRUE)>
<cfset request.attributeslist =
listappend(request.attributeslist,urlname,"&")>
<cfset request.attributeslist =
listappend(request.attributeslist,"1","=")>
</cfcatch>
</cftry>
</cfif>
</cfloop>
</cfif>
----- Original Message -----
From: "Brendan Avery" <[EMAIL PROTECTED]>
To: "Fusebox" <[EMAIL PROTECTED]>
Sent: Friday, December 08, 2000 5:18 PM
Subject: A suggestion to fix formurl2attributes "bug"
> This is a multi-part message in MIME format.
>
> ------=_NextPart_000_0098_01C06121.BC2106F0
> Content-Type: text/plain;
> charset="iso-8859-1"
> Content-Transfer-Encoding: 7bit
>
> Greetings fellow Fuseboxers. I think I was on this list a year or so ago
but
> somehow I lost track of it. Anyways, my name is Brendan Avery and I've
been
> using the Fusebox techniques for a year now -- kudos to Steve Nelson et al
for
> a very smart and efficient workaround to what would otherwise be major
> shortcomings of the CF platform. Anyways, on to the reason for this
email:
>
> FORMURL2ATTRIBUTES will throw an exception when you have incomplete
value-pair
> in the query-string (when using the standard ? prefix.) For example,
click
> the following:
> http://fusebox.org/index.cfm?oops
>
> See what I'm saying? Kind of tacky. Of course, you could always code in
an
> exception handler via cf_try/cf_catch to redirect to the index.cfm within
your
> index.cfm, but that might not be the desired result for some circuit
> applications (though it would probably be the most common, apart from a
custom
> error page.)
>
> However, I suggest that an alternative to coding exception handlers in the
> index.cfm would be a slight modification to the FormUrl2Attributes.cfm
script.
> See my modified version (attached); note I added very obvious comments
which
> could of course be truncated if this ever goes official.
>
> ONE OTHER NICE ADVANTAGE of this modified version of FormURL2Attributes is
> that it accepts any parameter declarations without an = sign and
accompanying
> value as a "TRUE" value, directly mimicing the behavior of a custom tag
with
> an unspecified attribute value. For Example, in the custom tag call:
>
> <CF_MYTAG THISWILLBETRUE>
>
> Within the MyTag.cfm, if you reference "attributes.thiswillbetrue" you
will
> get a TRUE value. This is the way cold fusion defines the default of an
> unvalued parameter.
>
> So, consider the following...
>
> http://whatever/index.cfm?fuseaction=report&textonly&maxrows=15
>
> With my modified formurl2attributes.cfm, you'll get the following
attributes:
>
> attributes.fuseaction = report
> attributes.textonly = TRUE
> attributes.maxrows = 15
>
> value of attributes.textonly will be returned as TRUE just like it would
be if
> you made the following cfmodule call to the index page like so:
>
> <cfmodule template="index.cfm" fuseaction="report" textonly maxrows=15>
>
> (Most importantly, however, it won't throw an exception if the index is
called
> by HTTP.)
>
> I had originally sent two emails to Steve Nelson regarding this
suggestion,
> but I guess he's too busy to answer, so I'm posting it here on the list to
see
> if anyone thinks this is a worthy addition to the official Fusebox
release.
>
> Thanks for your attention.
>
> --Brendan Avery / [EMAIL PROTECTED]
>
> ------=_NextPart_000_0098_01C06121.BC2106F0
> Content-Type: application/octet-stream;
> name="FormURL2Attributes.cfm"
> Content-Transfer-Encoding: quoted-printable
> Content-Disposition: attachment;
> filename="FormURL2Attributes.cfm"
>
> <cfsetting enablecfoutputonly=3D"yes">
> <!--- This tag will turn all 'Form' and 'URL' scoped variables into=20
> 'Attributes' scoped variables. This allows you to have a common scope=20
> of variables, thus allowing you to call the entire application i.e. =
> index.cfm
> as a CFMODULE or as a regular application.
> Designed for: CF 4.01+
> --->
> <cfparam name=3D"request.attributeslist" default=3D"">
> <cfparam name=3D"setfuseaction" default=3D"">
> <cfparam name=3D"attributes.displaybase" default=3D"yes">
> <cfparam name=3D"caller.id" default=3D"">
>
> <!--- This will convert URL variables to attribute variables --->
> <cfif isdefined("cgi.query_string") and isdefined("cgi.path_info")>
> <cfif not len(cgi.query_string)>
> <!--- This will support Search Engine capable URLs
> ex: =
> http://127.0.0.1/index.cfm/fuseaction/shoppingcart/additems/127,88/myvar/=
> hello+world --->
> <cfparam name=3D"cleanpathinfo" default=3D"#cgi.path_info#">
> =09
> <cfset findindex=3Dfindnocase("index.cfm",cleanpathinfo)>
> <cfif findindex>
> <cfset cleanpathinfo=3DRemoveChars(cleanpathinfo, 1, findindex+9)>
> </cfif>
> =09
> <cfif len(cleanpathinfo)>
> <!--- If you want to append .htm onto the end of your URL, this will =
> clean it=20
> so it doesn't affect your variables --->
> <cfif len(cleanpathinfo) gte 4 and right(cleanpathinfo,4) is ".htm">
> <cfset cleanpathinfo=3DRemoveChars(cleanpathinfo, =
> len(cleanpathinfo)-3, 4)>
> </cfif>
> =09
> =09
> <cfloop index=3D"i" from=3D"1" to=3D"#listlen(cleanpathinfo, "/")#" =
> step=3D"2">=20
> <cfset urlname =3D listgetat(cleanpathinfo, i, "/")>
> <cfif listlen(cleanpathinfo,"/") gte i+1>
> <cfset urlvalue =3D listgetat(cleanpathinfo, i + 1, "/")>
> <!--- This will allow you to pass slashes in your values, escape =
> your / with a slash_ --->
> <cfset urlvalue=3Dreplacenocase(urlvalue,"slash_","/","all")>
> <CFIF refindnocase("[[:alpha:]]",left(trim(urlname),1)) and NOT =
> ISDEFINED( 'caller.ATTRIBUTES.' & urlname )>
> <cfswitch expression=3D"#urlname#">
> <cfcase value=3D"cfid">
> <cfparam name=3D"url.cfid" default=3D"#urlvalue#">
> </cfcase>
> <cfcase value=3D"cftoken">
> <cfparam name=3D"url.cftoken" default=3D"#urlvalue#">
> </cfcase>
> <cfdefaultcase>
> <cfif urlvalue is "null">
> <cfset "caller.attributes.#urlname#" =3D "">=20
> <cfelse>=20
> <cfset "caller.attributes.#urlname#" =3D urlvalue>=20
> </cfif>
> <cfset request.attributeslist =3D =
> listappend(request.attributeslist,urlname,"&")>
> <cfset request.attributeslist =3D =
> listappend(request.attributeslist,urlencodedformat(evaluate("caller.attri=
> butes.#urlname#")),"=3D")>=09
> </cfdefaultcase>
> </cfswitch>
> </cfif>
> </cfif>
> </cfloop>
> </cfif>
> =09
> <!--- This is for converting url fields to attributes scoped variables =
> --->
> <cfelse>
> <cfloop list=3D"#cgi.query_string#" delimiters=3D"&" =
> index=3D"valuepair">
> <cfset URLName =3D "#ListGetAt(valuepair, 1, "=3D")#">=20
> <CFIF refindnocase("[[:alpha:]]",left(trim(urlname),1)) and NOT =
> ISDEFINED( 'caller.ATTRIBUTES.' & urlname )>
> <!---
> we need to make sure that the value exists in the url scope -- if it
> does, we can evaluate it. if it doesn't, then we're going to still
> create it and set it's value to TRUE. this just makes the tag a =
> little
> more robust and not error out on truncated or slightly malformed
> querystrings. note that the default value of TRUE was chosen to
> mirror the behavior of tag attributes when passed without a value.
> =09
> modification by http://brendanavery.com
> --->
> <cfif isdefined("url.#urlname#")>
> <cfset "caller.attributes.#urlname#" =3D =
> "#evaluate("url."&"#urlname#")#">
> <cfelse>
> <cfset "caller.attributes.#urlname#" =3D TRUE>
> </cfif> =09
> <!--- Remove these next 2 lines if you don't want a list of all =
> attributes...=20
> it'll speed up processing by about .15 millisecond--->
> <cfset request.attributeslist =3D =
> listappend(request.attributeslist,urlname,"&")>
> <cfset request.attributeslist =3D =
> listappend(request.attributeslist,urlencodedformat(evaluate("caller.attri=
> butes.#urlname#")),"=3D")>
> </CFIF>
> </cfloop>
> </cfif>
> </cfif>
>
> <!--- This is for converting form fields to attributes scoped variables =
> --->
> <cfif isdefined("form.fieldnames")>
> <cfloop list=3D"#form.fieldnames#" index=3D"field">
> <CFIF refindnocase("[[:alpha:]]",left(trim(field),1)) and NOT =
> ISDEFINED( 'Caller.ATTRIBUTES.' & trim(field) )>
> <cfset "caller.attributes.#trim(field)#" =3D =
> "#evaluate("form.#trim(field)#")#">
> <!--- This is so that you can have multiple type=3D"image" buttons on =
> the same page, if=20
> you name the button name=3D"fuseaction_[the value you want]" it will =
> set the fuseaction
> to that value--->
> <cfif findnocase("fuseaction_",field) and findnocase(".x",field)>
> <cfset setfuseaction=3Dreplacenocase(field,"fuseaction_","")>
> <cfset setfuseaction=3Dreplacenocase(setfuseaction,".x","")>
> <cfif refind("[0-9]",setfuseaction)>
> <!--- This is so you can associate an "ID" with an image button =
> (optional) like this:
> <INPUT type=3D"Image" src=3D"/IMAGES/MYIMAGE.GIF" =
> NAME=3D"fuseaction_addthisaddress56">
> it would return ID=3D56 That way you can a bunch of image buttons =
> in the same form
> that do the same thing but each one has an ID associated with it.
> --->
> <cfset =
> thisid=3Dval(mid(setfuseaction,refind("[0-9]",setfuseaction),len(setfusea=
> ction)))>
> <cfif thisid>
> <cfset caller.ID=3Dthisid>
> </cfif>
> </cfif>
> =09
> </cfif>
> <!--- Remove these next 2 lines if you don't want a list of all =
> attributes...=20
> it'll speed up processing by about .15 millisecond--->
> <cfset request.attributeslist =3D =
> listappend(request.attributeslist,trim(field),"&")>
> <cfset request.attributeslist =3D =
> listappend(request.attributeslist,urlencodedformat(evaluate("form.#trim(f=
> ield)#")),"=3D")>
> </cfif>
> </cfloop>
> </cfif>
> <cfif len(setfuseaction)>
> <cfset caller.attributes.fuseaction=3Dsetfuseaction>
> <cfif len(caller.id)>
> <cfset =
> caller.attributes.fuseaction=3Dreplace(setfuseaction,caller.id,"")>
> </cfif>
> </cfif>
>
> <!--- this is so that your relative images will work, this is only =
> needed if your using search engine urls --->
> <cfif attributes.displaybase>
> <CFSET caller.Base =3D REReplace(CGI.SCRIPT_NAME, "[^/]+\.cfm.*", "")>
> <CFSET caller.Base=3D "http://" & CGI.SERVER_NAME & caller.Base>
> <cfoutput><base href=3D"#caller.Base#"></cfoutput>
> </cfif>
> <cfsetting enablecfoutputonly=3D"No">
>
>
> ------=_NextPart_000_0098_01C06121.BC2106F0--
>
>
> Archives: http://www.mail-archive.com/[email protected]/
> Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists