Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outputting number of form fields submitted as well as values

Status
Not open for further replies.

infocusweb

Technical User
Jan 8, 2001
17
0
0
US
Hi Folks - How do I output the number of form fields submitted as well as the form field values? Thanks in advance.

http//
 
Code:
#ListLen(FORM.fieldnames)#

will give you the total number of form fields submitted, whether they had a value or not. (it will also give you all named field elements, if your submit button has a name attribute- it will be counted)

if you only want to count fields with values, you can do this
Code:
<cfset fieldcount = 0>

<cfloop list="#FORM.fieldnames#" index="i">

	<cfset current_field = "FORM." & #i#>
	<cfset current_value = Evaluate(#current_field#)>
	
		<cfif Len(#current_value#)>
			<cfset fieldcount = fieldcount + 1>
		</cfif>
		
</cfloop>
<br>
<cfoutput>#fieldcount#</cfoutput>
I realize there is probably a much more efficient way of getting the form value, but it's late and this is all i can come up with.


=========================================
I have not failed. I've just found 10,000 ways that won't work.
Thomas A. Edison
 
Hi,

As MX returns scopes as a structure you can use the collection attribute of the cfloop and iterate through them like this:

<CFLOOP COLLECTION="#Form#" ITEM="i">
<CFOUTPUT>
#i#&nbsp;&nbsp;#Form#<br>
</CFOUTPUT>
</CFLOOP>

This will mean that you then don't have to use the slow Evaluate function as well, which MM recommends to avoid.

HTH

Tony
 
I am not sure if you care about the format, but if you just want a list of form fields and their values for debugging purposes, you can use cfdump:

<cfdump var="#FORM#">

-Tek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top