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

Binding from cfc query to form fields

New Here ,
Jan 06, 2011 Jan 06, 2011

I wrote a simple cfc that houses a query pof my db. The query takes one argument that is the id of the record it is supposed to pull. What I am attempting to do is build a form to maintain the records of the db. In my form, I have a cfselect that allows the user to select the record from the db. The value of the cfselect is the id. I want the form to be populated with the query data from the cfc based upon the end users selection from the cfselect. I am getting it to pull the data from the cfc as I have dumped that to the page. I have not been successful in getting the form to populate with the data though. Here is my code...

My cfselect:

                        <cfselect name="webinar_classes" id="webinar_classes">
                            <cfoutput query="WebinarClasses">
                                <cfif WebinarClasses.currentrow is 1>
                                    <option value="#WebinarClasses.CLASSESID#" selected>#WebinarClasses.TITLE# #DateFormat(WebinarClasses.DATE, 'mm/dd/yy')#</option>
                                <cfelse>
                                    <option value="#WebinarClasses.CLASSESID#">#WebinarClasses.TITLE# #DateFormat(WebinarClasses.DATE, 'mm/dd/yy')#</option>
                                </cfif>
                            </cfoutput>
                        </cfselect>

My cfinput with the binding code:

<cfinput name="endTime" id="endTime" value="" size="3" bind="cfc:webinar_admin.cfc.webinar_admin.getEditendtime({webinarClassesedit:webinar_classes})" />

Any help would be appreciated.

4.4K
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
Contributor ,
Jan 06, 2011 Jan 06, 2011

Hi,

Use Firebug in Firefox, it may help to solve the problem.

Also, in your bind, you have so many .

It is something like this bind ="cfc: cfcname.Functionname(arguments to pass)"

Please verify

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
Community Expert ,
Jan 07, 2011 Jan 07, 2011

<cfselect name="webinar_classes" id="webinar_classes">
    <!--- The first option goes on top by default --->
    <option value="">Select</option>
    <cfoutput query="WebinarClasses">
            <option value="#WebinarClasses.CLASSESID#" selected>#WebinarClasses.TITLE# #DateFormat(WebinarClasses.DATE, 'mm/dd/yy')#</option>
    </cfoutput>
</cfselect>

The cfinput with the binding code:

<cfinput name="endTime" id="endTime" value="" size="3" bind="cfc:webinar_admin.cfc.webinar_admin.getEditendtime({webinar_classes})" />

We would then expect getEditendtime(id) to be a one-argument function which returns a string, based on the id passed to it.

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
New Here ,
Jan 07, 2011 Jan 07, 2011

Thank you for your feedback. Here is the function if this helps...

<cffunction name="getEditendtime" access="remote" returntype="string" description="cfc to return query results for webinar classes' endtime based upon cfselection" displayname="getEditendtime" hint="This cfc simply runs a query against the db of webinar classes. The parameter is to be supplied via a cfselect, but perhaps could utilize another variable input method.">
        <cfargument name="webinarClassid" type="string" required="yes">
        <cfquery name="WebinarClasses" datasource="activantcorpsitedb">
            SELECT WEBINARCLASSES.DATE, WEBINARCLASSES.ENDTIME, WEBINARCLASSES.WEBINARID, WEBINARCLASSES.ID AS 'CLASSESID', WEBINARS.ID AS 'WEBINARSID'
            FROM WEBINARCLASSES
            LEFT JOIN WEBINARS
            ON WEBINARS.ID = WEBINARCLASSES.WEBINARID
            WHERE WEBINARS.ID = WEBINARCLASSES.WEBINARID AND WEBINARCLASSES.DATE >= #Now()# AND WEBINARCLASSES.ID = #arguments.webinarClassid#
            ORDER BY WEBINARCLASSES.DATE
        </cfquery>
       
        <cfset editEndtime = #TimeFormat(WebinarClasses.ENDTIME,'short')#>

        <cfreturn editEndtime>
    </cffunction>

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
Community Expert ,
Jan 07, 2011 Jan 07, 2011

<cffunction name="getEditendtime" access="remote" returntype="string" description="cfc to return query results for webinar classes' endtime based upon cfselection" displayname="getEditendtime" hint="This cfc simply runs a query against the db of webinar classes. The parameter is to be supplied via a cfselect, but perhaps could utilize another variable input method.">
     <cfargument name="webinarClassid" type="string" required="yes">


    <!--- Make function variables function-local --->
    <cfset var datetimeObject=''>
    <cfset var editEndtime=''>

    <cfset var WebinarClasses = queryNew("","")>


    <!--- No need for lots of columns. You're only gonna return the endTime anyway --->
      <cfquery name="WebinarClasses" datasource="activantcorpsitedb">
          SELECT WEBINARCLASSES.DATE, WEBINARCLASSES.ENDTIME
          FROM WEBINARCLASSES
          LEFT JOIN WEBINARS
          ON WEBINARS.ID = WEBINARCLASSES.WEBINARID
          WHERE WEBINARS.ID = WEBINARCLASSES.WEBINARID AND WEBINARCLASSES.DATE >= #Now()# AND WEBINARCLASSES.ID = #arguments.webinarClassid#
          ORDER BY WEBINARCLASSES.DATE
      </cfquery>


      <cfset datetimeObject = parseDatetime(WebinarClasses.ENDTIME)>
      <cfset editEndtime = TimeFormat(datetimeObject,'short')>


      <cfreturn editEndtime>
  </cffunction>

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
New Here ,
Jan 14, 2011 Jan 14, 2011

Thanks for your help and the cleaning up of my code. My cfc is working just fine, but for some reason, I cannot get the binding to work. Here is my cfselect...

                        <cfselect name="webinar_classes" id="webinar_classes">
                            <cfoutput query="WebinarClasses">
                                <cfif WebinarClasses.currentrow is 1>
                                    <option value="">Select</option>
                                    <option value="#WebinarClasses.CLASSESID#" selected>#WebinarClasses.TITLE# #DateFormat(WebinarClasses.DATE, 'mm/dd/yy')#</option>
                                <cfelse>
                                    <option value="#WebinarClasses.CLASSESID#">#WebinarClasses.TITLE# #DateFormat(WebinarClasses.DATE, 'mm/dd/yy')#</option>
                                </cfif>
                            </cfoutput>
                        </cfselect>

Here is my cfinput binding...

<cfinput name="endTime" id="endTime" value="" size="3" bind="cfc:cfc.webinar_admin.getEditendtime(webinar_classes)" />

Thoughts?

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
Community Expert ,
Jan 14, 2011 Jan 14, 2011

getEditendtime({webinar_classes})

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
New Here ,
Jan 14, 2011 Jan 14, 2011

I saw that the curly braces were missing after my last post. I put them in and it still is not working. Thoughts?

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
Community Expert ,
Jan 16, 2011 Jan 16, 2011

<cfselect name="webinar_classes" id="webinar_classes">   
    <option value="">Select</option>
    <cfoutput query="WebinarClasses">
        <option value="#WebinarClasses.CLASSESID[currentrow]#">#WebinarClasses.TITLE[currentrow]# #DateFormat(WebinarClasses.DATE[currentrow], 'mm/dd/yy')#</option>
    </cfoutput>
</cfselect>

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
New Here ,
Jan 19, 2011 Jan 19, 2011

Thanks for the assist. I made the changes you suggested and the binding did not work. Any more thoughts?

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
Community Expert ,
Jan 19, 2011 Jan 19, 2011

Did the query populate the cfselect as expected?

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
New Here ,
Jan 19, 2011 Jan 19, 2011

Yes, but it was populating the cfselect prior to the code change. I just cannot seem to get the cfinput bound to the cfselect.


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
Community Expert ,
Jan 19, 2011 Jan 19, 2011

What is the path of the CFC from the web root, that is, from wwwroot?

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
Community Expert ,
Jan 19, 2011 Jan 19, 2011

If the path to the CFC is good, then the following test (in the same page as the cfform) should succeed. Does it?

<cfset testObj = createobject("component", "webinar_admin.cfc.webinar_admin")>
<cfset testResult = testObj.getEditendtime(a_suitable_value_of_classes_id)>
test result: <cfoutput>#testResult#</cfoutput>

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
New Here ,
Jan 19, 2011 Jan 19, 2011

Your test works, but my cfinput bind does not. Weird.


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
Community Expert ,
Jan 20, 2011 Jan 20, 2011

And without value attribute, thus(not that it should really matter)?

<cfinput name="endTime" id="endTime" size="3" bind="cfc:cfc.webinar_admin.getEditendtime({webinar_classes})" />

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
Community Expert ,
Jan 20, 2011 Jan 20, 2011

Yet another suggestion, assuming the cfform page and CFC are in the same directory

<cfinput name="endTime" id="endTime" bind="cfc:webinar_admin.getEditendtime({webinar_classes})" />

added edit: sorry about the multiple edits; I have trouble with my eyes today.

Message was edited by: BKBK

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
New Here ,
Jan 20, 2011 Jan 20, 2011

Thanks again for your help. I was thinking that since the earlier test worked but the form did not that it might be something with the form. I copied over the simple form from the docs with the auto-fill email address and that did not work. Do you suppose that it is something with either my form setup or within the CF server itself?

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
New Here ,
Jan 20, 2011 Jan 20, 2011

ok...I have given up with figuring out the bind issue. I am going to redesign. Thanks for all your help.

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
Community Expert ,
Jan 21, 2011 Jan 21, 2011

fs22 wrote:

Thanks again for your help. I was thinking that since the earlier test worked but the form did not that it might be something with the form. I copied over the simple form from the docs with the auto-fill email address and that did not work. Do you suppose that it is something with either my form setup or within the CF server itself?

I would do the following crucial test to verify whether the form setup is to blame:

<cffunction name="getEditendtime" access="remote" returntype="string" displayname="getEditendtime">
     <cfargument name="webinarClassid" type="string" required="yes">
     <cfset var editEndtime = "abc123">
     <cfreturn editEndtime>
</cffunction>

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
New Here ,
Jan 21, 2011 Jan 21, 2011

That worked.

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
Community Expert ,
Jan 21, 2011 Jan 21, 2011

fs22 wrote:

That worked.

It means the following code block is likely to blame:

  <cfquery name="WebinarClasses" datasource="activantcorpsitedb">
          SELECT WEBINARCLASSES.DATE, WEBINARCLASSES.ENDTIME
          FROM WEBINARCLASSES
          LEFT JOIN WEBINARS
          ON WEBINARS.ID = WEBINARCLASSES.WEBINARID
           WHERE WEBINARS.ID = WEBINARCLASSES.WEBINARID AND WEBINARCLASSES.DATE  >= #Now()# AND WEBINARCLASSES.ID = #arguments.webinarClassid#
          ORDER BY WEBINARCLASSES.DATE
      </cfquery>


      <cfset datetimeObject = parseDatetime(WebinarClasses.ENDTIME)>
      <cfset editEndtime = TimeFormat(datetimeObject,'short')>

Couldn't you just use something simpler, like

<cfquery name="WebinarClasses" datasource="activantcorpsitedb">
    SELECT DATE, ENDTIME
    FROM WEBINARCLASSES       
    WHERE DATE >= #Now()# AND ID = #arguments.webinarClassid#
    ORDER BY DATE
</cfquery>
<cfset datetimeObject = parseDatetime(WebinarClasses.ENDTIME)>
<cfset editEndtime = TimeFormat(datetimeObject,'short')>

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
New Here ,
Jan 21, 2011 Jan 21, 2011

I tried your query and it still did not work. Thanks anyway.


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
Community Expert ,
Jan 21, 2011 Jan 21, 2011

fs22 wrote:

I tried your query and it still did not work. Thanks anyway.


It means that the following query probably returns nothing

<cfquery name="WebinarClasses" datasource="activantcorpsitedb">
          SELECT WEBINARCLASSES.DATE, WEBINARCLASSES.ENDTIME
          FROM WEBINARCLASSES
          LEFT JOIN WEBINARS
          ON WEBINARS.ID = WEBINARCLASSES.WEBINARID
            WHERE WEBINARS.ID = WEBINARCLASSES.WEBINARID AND WEBINARCLASSES.DATE   >= #Now()# AND WEBINARCLASSES.ID = #arguments.webinarClassid#
          ORDER BY WEBINARCLASSES.DATE
      </cfquery>


      <cfset datetimeObject = parseDatetime(WebinarClasses.ENDTIME)>
      <cfset editEndtime = TimeFormat(datetimeObject,'short')>

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
New Here ,
Jan 21, 2011 Jan 21, 2011

No. The query does return something as I did a cfdump to the page and saw what it returned. Thanks anyway.

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