0
Detecting URL Parameters

/t5/coldfusion-discussions/detecting-url-parameters/td-p/617203
Mar 01, 2007
Mar 01, 2007
Copy link to clipboard
Copied
Total noob question here...
I am working on my first ColdFusion application. I have a query, outputted into a grid. Part of what I retrieve in the query is a unique id from each record in the database table. I use this id in the links I create beside each record row.
Example
<a href="client_update.cfm?ClientID=#ClientID#">edit</a>
Then, on the processing page, I use URL.ClientID to retrieve the correct record for updating. Easy enough...
Now, I want to wrap the Update SQL query on the processing page in a <cfif> condition that will detect whether that URL parameter exists, and if it doesnt, then use cflocation to redirect them away from the processing page and back to the form.
Example in vernacular :-)
If URL.ClientID doesnt exist
redirect them back to the form
Else
run the query
End
I tried a few techniques, but kept running into errors whenever I left off the clientID in the URL string. Suggestions...?
I am working on my first ColdFusion application. I have a query, outputted into a grid. Part of what I retrieve in the query is a unique id from each record in the database table. I use this id in the links I create beside each record row.
Example
<a href="client_update.cfm?ClientID=#ClientID#">edit</a>
Then, on the processing page, I use URL.ClientID to retrieve the correct record for updating. Easy enough...
Now, I want to wrap the Update SQL query on the processing page in a <cfif> condition that will detect whether that URL parameter exists, and if it doesnt, then use cflocation to redirect them away from the processing page and back to the form.
Example in vernacular :-)
If URL.ClientID doesnt exist
redirect them back to the form
Else
run the query
End
I tried a few techniques, but kept running into errors whenever I left off the clientID in the URL string. Suggestions...?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/detecting-url-parameters/m-p/617204#M57764
Mar 01, 2007
Mar 01, 2007
Copy link to clipboard
Copied
after your form submits, unless you pass the ClientID to the
action page
with the form data (i.e. in a hidden field) or via form tag's action
attribute (i.e. <from action="actionpage.cfm?ClientID=#url.ClientID#
...> the action page will not see any ClientID...
on the action page:
if you passed the clientid in a hidden field, check for a value of
passed hidden form field containing the clientid (i.e. <cfif
isdefined(" form.clientidfield") in your cfif statement
in the second case, check for url.clientid existence
--
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
with the form data (i.e. in a hidden field) or via form tag's action
attribute (i.e. <from action="actionpage.cfm?ClientID=#url.ClientID#
...> the action page will not see any ClientID...
on the action page:
if you passed the clientid in a hidden field, check for a value of
passed hidden form field containing the clientid (i.e. <cfif
isdefined(" form.clientidfield") in your cfif statement
in the second case, check for url.clientid existence
--
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Guest
AUTHOR
/t5/coldfusion-discussions/detecting-url-parameters/m-p/617205#M57765
Mar 01, 2007
Mar 01, 2007
Copy link to clipboard
Copied
Your reply made me go examine my attempts and I finally saw
what created the error.
The modified code below works as intended: checking for a URL parameter and, depending on whether or not it exists, selecting a simple course of action.
<cfif isDefined("URL.ClientID")>
<cfquery datasource="#dataSource#" name="getclientprofile">
SELECT *
FROM clients
WHERE ClientID = #URL.ClientID#
</cfquery>
<cfelse>
<cflocation url="client_master.cfm">
</cfif>
My error was in forgetting to enclose the URL.ClientID in quotation marks in the CFIF statement, as you have done in your example, which I am assuming at this point made CF interpret it as an undefined variable.
Thanks!
The modified code below works as intended: checking for a URL parameter and, depending on whether or not it exists, selecting a simple course of action.
<cfif isDefined("URL.ClientID")>
<cfquery datasource="#dataSource#" name="getclientprofile">
SELECT *
FROM clients
WHERE ClientID = #URL.ClientID#
</cfquery>
<cfelse>
<cflocation url="client_master.cfm">
</cfif>
My error was in forgetting to enclose the URL.ClientID in quotation marks in the CFIF statement, as you have done in your example, which I am assuming at this point made CF interpret it as an undefined variable.
Thanks!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advocate
,
LATEST
/t5/coldfusion-discussions/detecting-url-parameters/m-p/617207#M57767
Mar 02, 2007
Mar 02, 2007
Copy link to clipboard
Copied
Tige, your query looks like a good candidate for using
<cfqueryparam>. It should speed your query up and also
provide you a basic level of validation to make sure the data being
passed via the URL is what you are expecing.
The syntax is:
SELECT *
FROM clients
WHERE ClientID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#URL.ClientID#">
The syntax is:
SELECT *
FROM clients
WHERE ClientID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#URL.ClientID#">
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/detecting-url-parameters/m-p/617206#M57766
Mar 01, 2007
Mar 01, 2007
Copy link to clipboard
Copied
great! i am glad my reply helped!
just remember that your action page will see url.clientid var ONLY if it
is passed from the form page in the url scope: your form action attrib
has to include ?clientid=xxx ...
--
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
just remember that your action page will see url.clientid var ONLY if it
is passed from the form page in the url scope: your form action attrib
has to include ?clientid=xxx ...
--
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

