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

Get ID element from CFC

New Here ,
Oct 02, 2009 Oct 02, 2009

Copy link to clipboard

Copied

Hello -

I'm attempting to use my first CFC in conjunction with cfinput and autosuggest.  As is currently, everything works as far as the autosuggestion goes.  My simple  form is this:

<cfform action="#cgi.SCRIPT_NAME#">

     Client: <cfinput type="text"

                         name="client"

                         autosuggest="cfc:client.lookupClient({cfautosuggestvalue})" size="90">

<br />

  <input type="submit" value="Save">

</cfform>

My CFC is:

<cfcomponent output="false">

          <cfset THIS.dsn="myDSN">

     <!--- Lookup used for auto suggest --->    

     <cffunction name="lookupClient" access="remote" returntype="array">

     <cfargument name="search" type="any" required="false" default="">

     <!--- Define variables --->

     <cfset var data="">

     <cfset var result=ArrayNew(1)>

     <!--- Do search --->

     <cfquery datasource="#THIS.dsn#" name="data">

     SELECT clientID,firstName,lastName,email,organization  FROM client

     WHERE UCase(lastname) LIKE Ucase('#ARGUMENTS.search#%')

     ORDER by lastname, firstname

</cfquery>

<!--- Build result array --->

<cfloop query="data">

     <cfset name = '#lastname#, #firstname# (#email# - #organization#),  #clientID#'>  

     <cfset ArrayAppend(result, #name#)>

</cfloop>

<!--- And return it --->

<cfreturn result>  

   </cffunction>   

  </cfcomponent>

The data returns to the textbox formatted how I want it to be; however, when the  form submits, I only want the ID to post to the record.  How may I obtain the ID  from the CFC to use it in a hidden field of the form so the associated ID of the  client posts to the database record?

Thank you

TOPICS
Advanced techniques

Views

768

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
LEGEND ,
Oct 02, 2009 Oct 02, 2009

Copy link to clipboard

Copied

Your question is not clear.  What ID are you trying to obtain?

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
New Here ,
Oct 02, 2009 Oct 02, 2009

Copy link to clipboard

Copied

I apologize.  The textbox is populated with client information (lastname, firstname, email, organization) for staff to select the appropriate client.  I am trying to obtain the ID of the selected client so that when the form posts to the database, the clientID is saved to the table.

The way it is set up now, the staff are pleased as they see the relevant client information.  Staff do not care about the clientID.  On the other hand, I need the clientID so the record can be created in the database.  I don't care about the lastname, firstname, email or organization.

Thank you.

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
LEGEND ,
Oct 02, 2009 Oct 02, 2009

Copy link to clipboard

Copied

The query in your cfc selects the client id which eventually gets returned to the calling template.  Can we now say so far so good?  At what point do your problems begin.

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
New Here ,
Oct 02, 2009 Oct 02, 2009

Copy link to clipboard

Copied

Yes.  So far, so good.  I'm even pulling the ID into the textbox.  I can simply remove it from the textbox, but I want to include it in a hidden field so when the client name loads in the textbox, the associated ID loads in the hidden textbox.  Once the client is selected from the textbox, its ID will post with it when the form submits.

I do not know how to reference the CFC to get the ID value to put it in the hidden textbox.

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
LEGEND ,
Oct 03, 2009 Oct 03, 2009

Copy link to clipboard

Copied

If you can put the id into a text box, you can also put it into <input type="hidden">.

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
LEGEND ,
Oct 03, 2009 Oct 03, 2009

Copy link to clipboard

Copied

I do not know how to reference the CFC to get the ID value to put it in the hidden textbox.

You don't need to reference the CFC, you've got the ID in the value of the text box haven't you (along with the other data)? Extract the ID from that value; either on the clientside and pop it into an additional hidden field, or just extract it on the back-end once the form is submitted.

Is there any particular reason why you don't want to submit the whole value as displayed to the back end, or is it more that the back-end processing is only interested in the ID, and the rest is noise?

--

Adam

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
New Here ,
Oct 04, 2009 Oct 04, 2009

Copy link to clipboard

Copied

LATEST

The ID is the only element that posts to the database table that is of relevance. The client name, email and organization are only for my consultants to see so they select the correct client. The client ID is the only element that posts to the table.

I am unable to make the connection. If I do not have to reference the CFC to get the ID element to put into a hidden field, I don't know how to reference it in code. I am unfamiliar with any method or function to extract the data on the back end as well.

Client: <cfinput type="text" name="client" autosuggest="cfc:client.getClient()" size="90"> <br /> <cfinput type="hidden" value="cfc:client.getClient.ID">

This is what I thought would get the ID, but you say it does not have to reference the CFC to obtain the ID. How else may it be done?

Thank you.

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