views:

233

answers:

3

Hi I have a simple form

form.cfm:-

 <cfset Registr = createObject("component", "forms.Registr") /> 
 <cfset setFoo = createObject('component','forms.Registr).putNUsr(username,password,rating) />

    <form name="regFrm"  action="#cgi.script_name#" method="post" onsubmit="submitform();" >
      <tr><td>Username:</td>

    <td><input  type="text" name=" Username" value="#form. Username#" ></td></tr>


        <tr><td>Password:</td>
    <td><input class="" type="password" name="password" value="#form.password#" ></td></tr>     

        <tr><td>Rate:</td>

                <select name="rating" >
                    <option value="" ></option>
                    <cfloop query="qGetReting">
                        <option value="#rating_id#" <cfif form. rating eq prof_id>selected</cfif> >#rating#</option>
                    </cfloop>
                </select>
            </td>
        </tr>
    </form>

Now there is this cfc called Registr.cfc in the "forms" folder which has an insert-function called 'putNUsr'the code for 'Registr.cfc' is as follows.

<cfcomponent>
<cffunction name="putNUsr" returntype="void" displayname="" output="no">
        <cfargument name="password" type="string" required="true">
        <cfargument name="rating" type="numeric" required="true">        
        <cfargument name="username" type="string" required="true">    
            <cfquery datasource="#application.xyz#" name="q_putNUsr">
                insert into 
           users (username
                , password
                , rating)

                 values(                

            <cfqueryparam value="#arguments. username#" cfsqltype="CF_SQL_VARCHAR" />,          
            <cfqueryparam value="#arguments.password#" cfsqltype="CF_SQL_VARCHAR" />,
            <cfqueryparam value="#arguments.rating#" cfsqltype="CF_SQL_INTEGER"  )

                    </cfquery>
</cffunction>
 </cfcomponent>

I am able to populate the DB with the data if I do not use the form field "rating" which is numeric. Else i am getting the error as follows:-

The RATING argument passed to the putNUsr function is not of type numeric. 
If the component name is specified as a type of this argument, it is possible that either a definition file for the component cannot be found or is not accessible.

KINDLY HELP -S Vali

+1  A: 

The default (first) option item of your rating select passes an empty string to the putNUsr component. An empty string is not numeric and therefore fails the type validation.

You will have to put some additional logic into your putNUsr component to address that or simply set the default rating option in your form to 0 (as an example).

Andreas Schuldhaus
+2  A: 

You've defined the order of the parameters in your function as password, rating, username but your passing them in in the order username, password, rating.

You do have the option with ColdFusion as passing in the parameters as named-parameters eg putNUsr(username = 'me', password = 'letmein', rating = 5). When you do this you can pass them in in any order

Gary Boyle
you could also do:<cfset setFoo = createObject('component','forms.Registr).putNUsr(argumentCollection=form) />
rip747
+1  A: 

Gary already found your bug. Another thing regarding the rating is you could wrap it in the Val() function which will give you 0 for an empty string...

intnick