Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Detecting URL Parameters

Guest
Mar 01, 2007 Mar 01, 2007
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...?

4.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 01, 2007 Mar 01, 2007
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 01, 2007 Mar 01, 2007
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!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 02, 2007 Mar 02, 2007
LATEST
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#">
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 01, 2007 Mar 01, 2007
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources