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

cffunction valitation error

Participant ,
Mar 28, 2012 Mar 28, 2012

Hi,

I have a form where I  fill a customer-no. into an input field and get the customer name using databinding.

This works fine, but when I put non-numeric values into customer-no I get following error:

Error invoking CFC customer.cfc : The CUST_ID argument passed to the getcustomer function is not of type numeric. [Enable debugging by adding 'cfdebug' to your URL parameters to see more information]

The message is correct, but how can I avoid to run the getcustomer function when the value is not numeric?

Here is my code:

The form:

<cfinput type="text" name="customer_no" style="width:140;background-color:yellow" maxlength="10"  validate="integer" validateat="onblur"   message="Customer No. format is integer">

<cfinput type="text" name="customer_name" style="width:170" maxlength="200" bind="cfc:customer.getcustomer({customer_no})" readonly="yes">

customer.cfc:

<cfcomponent >

<cffunction name="getcustomer" access="remote" returntype="string" output="yes"  >

    <cfargument name="cust_id"   type="numeric"  required="true" >

  

                 <cfset  r_customer = "">

       

         <cfquery name = "select_customer" dataSource = "x">

        SELECT name

        FROM customer

        WHERE id =  <cfqueryparam   cfsqltype="cf_sql_numeric" value="#arguments.cust_id#" >

        </cfquery>

                 

<cfreturn r_customer>

</cffunction>

</cfcomponent>

1.2K
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

correct answers 1 Correct answer

Guide , Mar 28, 2012 Mar 28, 2012

Change the argument to type="any", then use isNumeric() inside your function. If it's not numeric, return an empty string.

Translate
Guide ,
Mar 28, 2012 Mar 28, 2012

Change the argument to type="any", then use isNumeric() inside your function. If it's not numeric, return an empty string.

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
Participant ,
Mar 28, 2012 Mar 28, 2012

Yes it works. Thank you very much!

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
Guide ,
Mar 28, 2012 Mar 28, 2012

Sometimes the simplest solutions are the best

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 ,
Mar 28, 2012 Mar 28, 2012
LATEST

biene22 wrote:

The message is correct, but how can I avoid to run the getcustomer function when the value is not numeric?

That is a trick question! The attribute bind="cfc:customer.getcustomer({customer_no})" implies that the function will run automatically, whether or not customer_no is numeric.

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