Skip to main content
Participating Frequently
August 22, 2007
Answered

forms and parameters

  • August 22, 2007
  • 9 replies
  • 893 views
Hi all,

I am trying to pass variables from a form to a .cfc with no success.

here's a simplified version of what I have (which is basically a compilation of adobe tutorial and documentation I've found):

***the initial .cfm***
input.cfm
*******************************************************************************************
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">

<head>
<title>addUser</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<!---First form: This form submits the end-user's search criteria--->
<form name="form1" action="update.cfm" method="post">
Test adding users: </br>
Enter a:
<p>clientid
<input type="text" name="clientid"/>
</p>
<p>user name
<input type="text" name="username"/>
</p>
<p>password
<input type="text" name="password"/>
<p>
<input type="submit" name="Submit"/>
</p>
</form>
</body>
</html>

***the called .cfm***
update.cfm
*******************************************************************************************
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">

<head>
<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<cfinvoke
component="dostuff"
method="addUser"
client= "#form1.clientid#"
uid= "#form1.username#"
pass= "#form1.password#">
</cfinvoke>
</body>
</html>

***the invoked function in this .cfc***
dostuff.cfc
*******************************************************************************************
<cfcomponent name="dostuff" output="false">

<cffunction name="addUser" access="remote" returnType="Struct">
<cfargument name="clientid" type="string" required="true"/>
<cfargument name="username" type="string" required="true"/>
<cfargument name="password" type="string" required="true"/>


... then i do "stuff" with these arguments here...

so, I consistently can't pass the arguments to my .cfc regardless of what the documentation says or what I try.

error thrown are usually something like... "Element USERNAME is undefined in FORM1"

any ideas out there?
This topic has been closed for replies.
Correct answer cf_dev2
> " The parameter USERNAME to function dostuff is required but was not passed in."

I suspect the problem now is a conflict with the names of the function arguments and <cfinvoke's> built-in attributes "userName" and "password". They will not be able to use cfinvoke unless they change names of their function arguments.


<cffunction name="addUser" access="remote" returnType="Struct">
<cfargument name="clientid" type="string" required="true"/>
<cfargument name="theUserName" type="string" required="true"/>
<cfargument name="thePassword" type="string" required="true"/>
...

<cfinvoke
component="dostuff"
method="addUser"
clientID= "#form.clientid#"
theUserName= "#form.username#"
thePassword= "#form.password#">
</cfinvoke>


Another option is to call the function this way

Not tested
<cfset stuffObj = createObject("component", "dostuff") />
<cfset result = stuffObj.addUser(clientId=form.clientId,
userName=form.userName,
password=form.password) />







9 replies

Inspiring
August 23, 2007
> You could also pass the entire form scope as an argumentCollection

That's another good method
Participating Frequently
August 23, 2007
Good catch on the form scope naming error. I was completely blind to the 1 in my previous answer and concentrating too much on the argument naming.

You could also pass the entire form scope as an argumentCollection.

i.e.
<cfinvoke component="processForm" argumentcollection="#Form#" method="dumpForm">

-----
<cfcomponent>
<cffunction name="dumpForm" access="public">
<cfdump var="#Arguments#">
</cffunction>
</cfcomponent>
Inspiring
August 23, 2007
I'm glad you got it working.

Btw, I realized I forgot to mention a possible 3rd option. Not tested but, you might be able to use cfinvoke if you pass the argument names "userName" and "password" through cfinvokeargument tags.

<cfinvoke component="dostuff" method="addUser">
<cfinvokeargument name="clientID" ...>
<cfinvokeargument name="userName" ...>
<cfinvokeargument name="password" ...>
</cfinvoke>


ctauerAuthor
Participating Frequently
August 23, 2007
Thanks for that tip.

I had actually tried this method, as well, in my various attempts. I was not successful, but I might try to apply what I've learned here to that other method just to see if I can get that working, too.

What I've seen in the documentation says:
"Using the cfinvokeargument tag, for example, you can build conditional processing that passes a different parameter based on user input."

So, that might come in handy later down the road, and I think my main hang up with that method may have simply been using the form name and not the more general FORM in my reference.
ctauerAuthor
Participating Frequently
August 23, 2007
So, that was indeed the final problem.

The two problems that I had were using FORM and not the form name, and then the conflict between the function arguments and <cfinvoke's> built in attributes "username" and password".

Thanks to everyone who helped.
Inspiring
August 22, 2007
Also, "password" is also a built-in argument name for cfinvoke. IIRC you will probably need to change name of your function argument to something other than "password" or cfinvoke will not work.

Edit - Looks like "userName" is also a built-in argument name so you'll have to use a different name for that argument too


Inspiring
August 22, 2007
Either case will work. ColdFusion is not case sensitive.

I supsect your cfinvoke is still using "uid" instead of "username" as c_wigginton mentioned. If your function requires 3 arguments named:

clientID
userName
password

Your cfinvoke must use those same names for the arguments.

<cfinvoke
component="dostuff"
method="addUser"
clientID= "#form.clientid#"
userName= "#form.username#"
password= "#form.password#">
</cfinvoke>
ctauerAuthor
Participating Frequently
August 22, 2007
Thanks for the reply....I was hoping you were right. I had tried that, too; however, I couldn't remember if I used upper case FORM instead of form. I seem to remember something about Coldfusion being case sensitive.

But, it didn't work either. The error I get is:

" The parameter USERNAME to function dostuff is required but was not passed in."

Any other ideas?
Inspiring
August 23, 2007
quote:

Originally posted by: ctauer
Thanks for the reply....I was hoping you were right. I had tried that, too; however, I couldn't remember if I used upper case FORM instead of form. I seem to remember something about Coldfusion being case sensitive.

But, it didn't work either. The error I get is:

" The parameter USERNAME to function dostuff is required but was not passed in."

Any other ideas?

You had name mismatches on all three arguments in your original post. Did you fix all three, or just the one that was pointed out to you?
cf_dev2Correct answer
Inspiring
August 23, 2007
> " The parameter USERNAME to function dostuff is required but was not passed in."

I suspect the problem now is a conflict with the names of the function arguments and <cfinvoke's> built-in attributes "userName" and "password". They will not be able to use cfinvoke unless they change names of their function arguments.


<cffunction name="addUser" access="remote" returnType="Struct">
<cfargument name="clientid" type="string" required="true"/>
<cfargument name="theUserName" type="string" required="true"/>
<cfargument name="thePassword" type="string" required="true"/>
...

<cfinvoke
component="dostuff"
method="addUser"
clientID= "#form.clientid#"
theUserName= "#form.username#"
thePassword= "#form.password#">
</cfinvoke>


Another option is to call the function this way

Not tested
<cfset stuffObj = createObject("component", "dostuff") />
<cfset result = stuffObj.addUser(clientId=form.clientId,
userName=form.userName,
password=form.password) />







ctauerAuthor
Participating Frequently
August 22, 2007
Thanks for the response....I think I understand that you're saying the argument name and the parameter being passed in the attribute format have to match?

This is where I started, and I just tried it again. It doesn't work. With the same error I listed.

Any other ideas?
Inspiring
August 22, 2007
When you use method="post", form variables are always passed in a scope named "FORM" (not the name of your form). Use #FORM.username# instead of #FORM 1.username#
Participating Frequently
August 22, 2007
on the invoke, you're setting
uid= "#form1.username#"

but in the component function
you've specified username as the argument name,
try
<cfargument name="uid" type="string" required="true" />

And that's only your first failure
you also need to fix pass vs password