3 Replies Latest reply on May 21, 2009 7:51 AM by CFmonger

    Select function issue

    CFmonger Level 1


      I am trying to write a little nav using a select menue. This page is a dynamic page, you can only get to it when there is an URL.ID, if there is not one, it kicks you back to the page that spawns the details page. I have it locked down pretty well with the url.ID, I added the select nav on the detail page so people won't have to go back to the main page for the list of records in that part of the db, and they won't have to cycle through number 1-12 to find a record they want to pull up.I have 2 queries running this. I will comment it out and mainly focus on the select function.


      This is the MAIN query, this one runs the page and outputs the info for the details of the records I am bring up. This works fine from the main page link using url.id


      <cfquery name="GetRecordevent" datasource="#APPLICATION.dataSource#">
      SELECT events.display AS ViewField1, events.title AS ViewField2, events.eventDate AS ViewField3, events.eventTime AS ViewField4, events.location AS ViewField5, events.contact AS ViewField6, events.phone AS ViewField7, events.fax AS ViewField8, events.email AS ViewField9, events.URL AS ViewField10, events.sponsor AS ViewField11, events.Body AS htmlList, events.ID AS ID
      FROM events
      WHERE events.ID =<cfqueryparam value="#URL.ID#" cfsqltype="cf_sql_integer">


      now this is the tag that locks down the detail page:


      <cfif (isDefined ("URL.ID")) OR (isDefined ("value.id"))>

      they get the info on this page

      <cflocation url="index.cfm" addtoken="no">


      this is the select function and query that populates it with the titles of records and the id


      <CFQUERY name="cata" datasource="#APPLICATION.dataSource#" cachedwithin="#CreateTimeSpan(0, 6, 0, 0)#">
      SELECT events.title AS ViewField2, events.ID AS ID
      FROM events


      <cfform Name="eventnav" method="post" Action="detail.cfm?value=#ID#">
           <select name="ID" size="1" class="selectstyle" onChange="eventnav.submit();">
           <option value=""> --Select an Event-- </option>
               <CFOUTPUT query= "cata">
               <option value="#ID#">#ViewField2#</option>


      now my query is not recognizing the value.id in the url from the select function action part of the form. I tried adding a AND statement and changed it to an OR statement, neither one works. What do I need to do to either change the select function to match a url.id or add to my main query that the select function needs to pull a record?I'm a little confused, my lockdown works as it is with teh OR in it. But my main query is not liking what I am doing.Can anyone help me figure out how to make this work properly?Thank you.Codemonger

        • 1. Re: Select function issue
          ilssac Level 5

          CFmonger wrote:


          <cfform Name="eventnav" method="post" Action="detail.cfm?value=#ID#">


          method="post" means that the data will be submitted as post data in the request which will populate the FORM structure which is different from the URL structure that comes from get data in a request.


          The fastest way to fix this would be to change the method parameter to "get" in your cfform tag.


          There are also frameworks out there that blend the form and url scopes together so that you do not have to worry about which the data came from.  Fusebox is one such framework.  But doing something like that would be a lot of re-engineering if you have a lot of existing code.


          Otherwise you could work your logic to look for the ID value in either the URL or the FORM scopes.


          P.S. the ?value=#ID# I just noticed in the action parameter will be populated with the current ID on the page, not the new ID selected by the user from the select control.  So this form is going to submit both POST and GET data with ID values, but those values will be distinct and often different.

          • 2. Re: Select function issue
            Dan Bracuk Level 5

            The most likely source of your problem is that you are using two variable names when one is enough.  Try changing this

            <cfform Name="eventnav" method="post" Action="detail.cfm?value=#ID#">

            to this

            <cfform Name="eventnav" method="post" Action="detail.cfm?id=#ID#">

            • 3. Re: Select function issue
              CFmonger Level 1

              Thank you! That wrked, it works nice now. Appreciate the help!