4 Replies Latest reply on Sep 22, 2006 8:43 AM by Newsgroup_User

    CFC argument passing problem.

    Level 7
      What is wrong with this? I have a form that passes 3 elements to a cfc for
      insert. It is telling me that I am not passing the title.

      This is my CFC:
      <cffunction name="AddJob" access="public" returntype="void">
      <cfargument name="title" required="yes" type="string">
      <cfargument name="doc" required="yes" type="string">
      <cfargument name="cats" required="yes" type="numeric">
      <cffile action="upload" destination="E:/www/contactus/employment"
      nameconflict="overwrite" filefield="doc">
      <cfquery name="Addjob" datasource="***">
      INSERT INTO EmpJobs (title, doc, catid)
      VALUES ('#arguments.title#', '#cffile.serverfile#', #arguments.cats#)
      </cfquery>
      </cffunction>

      This is the Submit Code:
      <cfif IsDefined ('Add_Job')>
      <cfinvoke component="#Jobs#" method="AddJob">
      <cfinvokeargument name="title" value="#Form.title#">
      <cfinvokeargument name="doc" value="#Form.doc#">
      <cfinvokeargument name="cats" value="#Form.catid#">
      <cflocation url="index.cfm" addtoken="no">
      </cfif>

      This is the form.
      <form action="" method="post" enctype="multipart/form-data" name="add"
      id="add">
      <table width="100%" border="0">
      <tr>
      <td width="20%"><div align="right">Job Title:</div></td>
      <td width="80%"><input name="title" type="text" id="title"
      size="45" /></td>
      </tr>
      <tr>
      <td><div align="right">Description Document: </div></td>
      <td><input name="doc" type="file" id="doc" /></td>
      </tr>
      <tr>
      <td><div align="right">Employment Category: </div></td>
      <td><select name="catid" id="catid">
      <cfoutput query="GetCats">
      <option value="#empid#">#cat#</option>
      </cfoutput>
      </select> </td>
      </tr>
      <tr>
      <td> </td>
      <td><input name="Add_Job" type="submit" id="Add_Job" value="Add
      New Job Posting" /></td>
      </tr>
      </table>
      </form>

      What am I missing? Thanks!


        • 1. Re: CFC argument passing problem.
          azadisaryev Level 1
          1) i do hope you have action attribute defined for the form, not an empty string as in your code sample... if you comment out <cfargument name='title' ...> line in your cfc, is it telling you that you are not passing 'doc' now?
          2) as your code seems to be all good, maybe try renaming the form field in question to 'jobtitle'... and of course change this name in your cfc and in cfinvokeargument tags
          • 2. Re: CFC argument passing problem.
            Dan Bracuk Level 5
            cfdump/cfabort are your freinds.

            Use it with your form before your cfinvoke tag.

            Make all your cfarugments optional and then use the dump/abort on your arguments, right after the cfargument tags.
            • 3. Re: CFC argument passing problem.
              Level 7
              Everything in your code seems to be fine.
              Try general debugging using CFDUMPS. If does not work try passing the whole
              form object to the method : -

              Submit Code:
              > <cfif IsDefined ('Add_Job')>
              > <cfinvoke component="#Jobs#" method="AddJob">
              > <cfinvokeargument name="FormObj" value="#Form#">


              CFC:
              > <cffunction name="AddJob" access="public" returntype="void">
              > <cfargument name="FormObj" required="yes" type="struct">

              > <cfquery name="Addjob" datasource="***">
              > INSERT INTO EmpJobs (title, doc, catid)
              > VALUES ('#arguments.FormObj.title#', '#cffile.serverfile#',
              #arguments.FormObj.cats#)
              > </cfquery>
              > </cffunction>


              • 4. Re: CFC argument passing problem.
                Level 7
                You don't have a closing <cfinvoke> tag after the <invokearguments>, so CF
                is thinking you're not passing any args into the <cfinvoke> call.

                This is one place where I think CF should enforce having an explicit
                closing tag.

                --
                Adam