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

Question about <cfdiv bind

Explorer ,
Jun 05, 2012 Jun 05, 2012

Copy link to clipboard

Copied

I'm trying to create a page that displays the results of a query, but will allow you to filter them by date, name, etc. I'm relatively new to this concept, but reading a bit online I found some examples that did what I'm trying to do. I have a few questions and a problem though, if someone is willing to provide a bit of guidance. If it matters, I'm using cf9.

First, can you use a <cfdiv bind to submit multiple url parameters? If so, do I just use a semicolon to separate them like this:

<cfdiv bind="url:mypage.cfm?param1={value1};param2={value2}" />

Second, if you can use this functionality, what's the best way to send dates as url parameters? URLEncodedFormat() and then URLDecode()? All the examples of those tags surround them with # to indicate variables, but since you don't use that notation in a cfdiv bind, do I just put the whole thing inside the {} like this (and then use URLDecode(mydate) on the action page):

<cfdiv bind="url:mypage.cfm?date1={URLEncodedFormat(mydate)} />

Third, I'm having trouble getting the <cfdiv bind to display at all. I have an action page set up (mypage.cfm) that loads fine in a browser, but when I try to add it to another page like this, it doesn't work:

<cfdiv bind="url:mypage.cfm" />

I'm assuming this is because I'm not submitting any parameters on this page to be processed on mypage.cfm, but I don't know if that's true. I'm trying to get the div to display first, then add the dynamic form to filter the results, but maybe it doesn't work that way?

Thanks for any help!

Jeremy

Views

3.4K

Translate

Translate

Report

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
Valorous Hero ,
Jun 05, 2012 Jun 05, 2012

Copy link to clipboard

Copied

First, can you use a <cfdiv bind to submit multiple url parameters? If so, do I just use a semicolon to separate them like this:

Yes. However the parameters are separated with an ampersand ie "&" just like any url.

Second, if you can use this functionality, what's the best way to send dates as url parameters? URLEncodedFormat() and then URLDecode()? All the examples of those tags surround them with # to indicate variables, but since you don't use that notation in a cfdiv bind, do I just put the whole thing inside the {} like this (and then use URLDecode(mydate) on the action page):

<cfdiv bind="url:mypage.cfm?date1={URLEncodedFormat(mydate)} />

Depends on the source. If you are binding to a form field that contains a date, you do not need to do anything. CFDIV escapes the values of bound fields automatically.

        <form>

             <input type="text" id="someFormField" ...>

        </form>

        <cfdiv bind="url:mypage.cfm?date1={someFormField}" />

You only need to encode static values:

        <cfset text = "20% discount">

        <cfdiv bind="url:mypage.cfm?someValue=#URLEncodedFormat(text)#" />

Third, I'm having trouble getting the <cfdiv bind to display at all. I have an action page set up (mypage.cfm) that loads fine in a browser, but when I try to add it to another page like this, it doesn't work:

It is hard to say without seeing the relevant code. What do you mean by "doesn't work"? Are you getting an error, blank screen, ...?  Post the code and error message.

Assuming you are using a local dev server, be sure to enable ajax debugging so you can see the ajax requests going on in the background.

      http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec10e40-8000.html

Votes

Translate

Translate

Report

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
Explorer ,
Jun 06, 2012 Jun 06, 2012

Copy link to clipboard

Copied

Thank you, I was able to get it mostly working. There was an issue with the server on my system so I had to re-install Coldfusion. It dawned on me that I had cleaned up some files that I was no longer using and might have accidentally gotten rid of something important.

So it's definitely better now. I can change the dates so that I can display records that fall within those date parameters. What I'm trying to do now is be able to sort the records, and I'm having trouble with that. Right now I have a select menu named "sort" with a bunch of values that reference elements in the table: Last Name (Lname), Date Submitted (Reptime), and Date of Absence (Absence_Date). Then in my sql I have "ORDER BY <cfparam value="#url.sort# cfsqltype="cf_sql_varchar">. I don't get any errors or anything, I just don't get any changes to the displayed data. Here's my sql, the commented parts are not in the file, I added those for explanation here:

<!--- There are two radio buttons to toggle between viewing all records and viewing the selected records based on the date parameters. This sets the start and end dates when view all is selected --->


<cfif IsDefined("url.viewAll") AND #url.viewAll# EQ "yes">

  <cfset startDate="01/01/2012">

  <cfset endDate="12/12/2020">

<cfelse>


<!--- This sets the start and end dates based on the items in those fields if view all is not selected, and sets the dates to the view all dates if the date entry fields are empty --->


  <cfif IsDefined("url.startDate") AND #url.startDate# NEQ "">

    <cfset startDate="#url.startDate#">

  <cfelse>

    <cfset startDate="01/01/2012">

  </cfif>

  <cfif IsDefined("url.endDate") AND #url.endDate# NEQ "">

    <cfset endDate="#url.endDate#">

  <cfelse>

    <cfset endDate="12/12/2020">

  </cfif>

</cfif>


<!--- Defines the url.sort parameter and sets the default in the event no selection is made on the page. --->


<cfparam name="url.sort" default="Absence_Date">


<!--- And my query. Pretty self-explanatory, but the ORDER BY portion isn't working. Records are displayed in the order they appear in the database, which is the submit time (Reptime) --->


<cfquery name="absences" datasource="ctband">

  SELECT *

  FROM Absences

  WHERE Absence_Date > <cfqueryparam value="#startDate#" cfsqltype="cf_sql_varchar"> AND Absence_Date < <cfqueryparam value="#endDate#" cfsqltype="cf_sql_varchar">

  ORDER BY <cfqueryparam value="#url.sort#" cfsqltype="cf_sql_varchar">

</cfquery>

Votes

Translate

Translate

Report

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
Valorous Hero ,
Jun 06, 2012 Jun 06, 2012

Copy link to clipboard

Copied

LATEST

  ORDER BY <cfqueryparam value="#url.sort#" cfsqltype="cf_sql_varchar">

CFQueryparam is designed to prevent values from being executed as a sql command. So you cannot use it to represent column names. You need to use a different method to protect your order by clause. For example:

               <cfif listFindNoCase("(list of valid column names"), url.sort)>

                       ORDER BY #url.sort#

               </cfif>

WHERE Absence_Date > <cfqueryparam value="#startDate#" cfsqltype="cf_sql_varchar">

As an aside, if Absence_Date is a date/time column the correct sql type is either cf_sql_timestamp or cf_sql_date.  Avoid using varchar on dates because the value will be passed as a string, rather than a date object, which forces the database to parse the string using its own internal rules. So the end result might not be what you expect.

<cfif IsDefined("url.endDate") AND #url.endDate# NEQ "">

Though there is nothing technically wrong with isDefined, structKeyExists is generally preferred because it is more precise.  Also a) there is no need for those # signs and b) consider using cfparam to assign default date values instead to simplify the code.

Votes

Translate

Translate

Report

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
Documentation