Skip to main content
Known Participant
November 27, 2008
Question

2 forms on same page

  • November 27, 2008
  • 7 replies
  • 848 views
Is it possible in Coldfusion(v8) to have 2 forms on the same page, name them and return the variable.

Something like this. although the form variable is a system variable so how would it work?

<cfdump var="#form.username#"></cfdump>
<cfdump var="#form2.email#"></cfdump>
This topic has been closed for replies.

7 replies

HulfyAuthor
Known Participant
December 4, 2008
That's what was confusing me. So either name the submit or a hidden variable would do the trick.

This kind of answers my other question.
BKBK
Community Expert
Community Expert
December 4, 2008
Hulfy wrote:
...name them and return the variable

Do you mean something like this?

<FORM action="actionPage.cfm" method="post" name="myForm">
User: <INPUT type="text" name="username"><BR>
<INPUT type="submit" name="sbmt1" value="Send">
</FORM>

Then refer to the variable myForm.username? That may work in Javascript and other scripting languages, but I don't expect it will in Coldfusion. Upon submit, Coldfusion returns its own form structure, named, what else, form.

BKBK
Community Expert
Community Expert
November 29, 2008
<!--- use sbmt1, sbmt2 to distinguish between the submitted forms --->
<cfif isDefined("form.sbmt1")>
<cfset form1=form>
<cfelseif isDefined("form.sbmt2")>
<cfset form2=form>
</cfif>

<cfif isDefined("form1.username")>
form1.username: <cfoutput>#form1.username#</cfoutput><br>
form1 dump <cfdump var="#form1#">
</cfif>

<cfif isDefined("form2.email")>
form2.email: <cfoutput>#form2.email#</cfoutput><br>
form2 dump <cfdump var="#form2#">
</cfif>



<cfoutput><FORM action="#cgi.script_name#" method="post"></cfoutput>
User: <INPUT type="text" name="username"><BR>
<INPUT type="submit" name="sbmt1" value="Send">
</FORM>
</P>

<P>
<cfoutput><FORM action="#cgi.script_name#" method="post"></cfoutput>
Email: <INPUT type="text" name="email"><BR>
<INPUT type="submit" name="sbmt2" value="Send">
</FORM>
</P>


Inspiring
November 27, 2008
What are you trying to do and what is happening when you try?
HulfyAuthor
Known Participant
November 27, 2008
I can't get it to work can someone post an exmaple please?

Thanks
BKBK
Community Expert
Community Expert
November 27, 2008
What Daverms says, plus

<cfif isDefined("form.username")>
<cfoutput>#form.username#</cfoutput>
or
<cfdump var="#form#">
</cfif>

<cfif isDefined("form2.email")>
<cfoutput>#form2.email#</cfoutput>
or
<cfdump var="#form2#">
</cfif>

Inspiring
November 27, 2008
Yeah... You can have.. But you can submit one at a time...