Skip to main content
Participant
November 30, 2010
Question

Please help!!! This expression must have a constant value

  • November 30, 2010
  • 2 replies
  • 2568 views

I try to work with cfc and cfinvoke and not sure why I got this error. Searched

in google for answer but still don't get any. Can anyone help please...not sure where

I had it wrong...I thought my codes should work (?)

When a form is submitted I have this codes in formaction.cfm, I captured all the form fields in a structure:

<CFSET st_Registration = {Salutation="#Trim(Form.Salutation)#", FName = "#Trim(Form.FName)#", MName = "#Trim(Form.Mname)#",LName =  "#Trim(Form.LName)#" .......etc }/>

Then I set all the required fields:

<CFSET ReqFields ="Salutation,FName,LName,Addr1,City,State,Zip,Country,Phone,Email,username,password">

<!--- Then send the structure and req. fiels list to a function located in a component to verify required fields --->

<cfset CreateUserInfo = createObject("component", "airbucks.cfcomp.VerifyInput").init()>

<CFINVOKE component="#CreateUserInfo#" method="Verify_ReqFields" st_Registration = "#st_Registration#" RequiredFields ="#ReqFields#" returnvariable="VerifyResult">

<CFIF #VerifyResult# IS "">
<cfdump var="#st_Registration#">
<CFELSE>
  <CFIF #st_Registration["Country"]# IS "USA">
<CFINCLUDE template="registration_ret.cfm">
  <CFELSE>
<CFINCLUDE template="registration_other_ret.cfm">
  </CFIF>
</CFIF>

<!--- Below is part of the component with the function for checking required fields --->

<cfcomponent displayname="VerifyInputData" output="false">

<CFFUNCTION name="Init" access="public" returntype="any" output="false" hint="Returns an initialized component instance.">

<!--- Return This reference. --->

<cfreturn THIS />

</CFFUNCTION>

<!--- Verify required fields --->

<CFFUNCTION name="Verify_ReqFields">

<cfargument name="st_Registration" type="struct" required="true">

<cfargument name="RequiredFields" type="string" required="true">

<!--- check if req. fields are blank --->

<CFSET ErrorList = "">

<cfloop collection="#arguments.st_Registration#" item="KEY">

<CFIF #Trim(st_Registration[KEY])# IS "">

<CFSWITCH expression="#Trim(KEY)#">

<CFCASE value="#arguments.RequiredFields#">

<CFSET ErrorList = ListAppend(ErrorList, "#KEY#")>

</CFCASE>

</CFSWITCH>

</CFIF>

</cfloop>

<CFRETURN ErrorList >

</CFFUNCTION>

 

 

</cfcomponent>

Here is the error:

The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request

This expression must have a constant value.

The error occurred in C:\Inetpub\wwwroot\AirBucks\registrationaction.cfm: line 55
53 :                              
54 : <!--- Verify required field based on the required list set above --->
55 : <cfset CreateUserInfo = createObject("component", "airbucks.cfcomp.VerifyInput").init()>
56 : <CFINVOKE component="#CreateUserInfo#" method="Verify_ReqFields" st_Registration = "#st_Registration#" RequiredFields ="#ReqFields#" returnvariable="VerifyResult">
57 :      

This topic has been closed for replies.

2 replies

Inspiring
November 30, 2010

It's bubbling up a compiler error.  It's not line 55 that's the problem, it's that /airbucks/cfcomp/VerifyInput.cfc has syntax errors in it, namely you have a runtime value for the value of your <cfcase> statements, which is illegal.  So the file can't compile, so your createObject() call fails.

--

Adam

Inspiring
November 30, 2010

I'm not sure if any of this is causing your error, but I have the following observations.

First, given that a form is a structure, creating a new one is inefficient.

Next, you don't need trailing slashes in cftags.

Next, you don't need octothorps inside tags.

What might be happening is that CF is giving you the wrong line number for your error.  It's probably line 56.  When you create an object from a component, you don't use cfinvoke to call it's methods.  You just call them like this:

your_return_variable = your_object.your_function(arguments go here);

You use cfinvoke on the component itself.

CF_EKingAuthor
Participant
November 30, 2010

Thank you and I'll change my codes.

When I did the following, I still get the same error.

Isn't it CreateUserInfo is the object?

<cfset CreateUserInfo = createObject("component", "airbucks.cfcomp.VerifyInput").init()>

<CFSET VerifyResult = CreateUserInfo.Verify_ReqFields(st_Registration, ReqFields)>

Using cfinvoke used to work.

The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request

This expression must have a constant value.

The error occurred in C:\Inetpub\wwwroot\AirBucks\registrationaction.cfm: line 54
52 : <!--- Verify required field based on the required list set above --->
53 : 
54 : <cfset CreateUserInfo = createObject("component", "airbucks.cfcomp.VerifyInput").init()>
55 : <!---
56 : <CFINVOKE component="#CreateUserInfo#" method="Verify_ReqFields" st_Registration 

CF_EKingAuthor
Participant
November 30, 2010

Just to respond to my own posting, I found out that I can use #variable# in CFCASE. That's the error source on this case.

But thank you for the advice given, I'll follow proper coding. Thanks again.