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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop through form results

Status
Not open for further replies.

theotrain

Programmer
Mar 5, 2003
150
MX
Hola,

I want to display ALL the contents of a Form that has been submitted to the current page.

i tried
Code:
<cfdump var=&quot;#form#&quot;>
but it only returned the first bit of the form (my form is dynamically generated, and has a potentially changing number of elements). Is this a flaw in my form or does CF not accept this usage of cfdump?

is there a better way?
 
You can loop through the form structure like this:
Code:
<cfloop index=&quot;thefield&quot; list=&quot;#form.fieldnames#&quot;>
  <cfset fields=&quot;#thefield# = #evaluate(thefield)#&quot;>
  <cfoutput>#fields#</cfoutput><br>
</cfloop>

There are a couple of different ways to word that, but this one works.

Have fun.


Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
Hmmm...
Code:
<CFDUMP var=&quot;#FORM#&quot;>
should, indeed, dump out all form fields. If CFDUMP is only outputting a portion of your form, then, yes, I'd say you have some potential problems with the form itself.

One thing that might cause CFDUMP to fail are, under 5.0 CFDUMP wasn't smart enough to escape &quot;<&quot;'s... so if the content of the variable you were trying to CFDUMP contains HTML, the output could possibly get a little mangled.

Other than that, CFDUMPing the FORM scope will dump all form fields that that template received.

Travis' solution using
Code:
FORM.fieldnames
will more than likely not produce any more meaningful results (CFDUMP will be far more robust), and actually doesn't follow Macromedia's official guidelines for this type of functionality.
Code:
FORM.fieldnames
is notoriously unreliable... especially if you have multiple fields with the same name on your form (checkboxes, radio buttons, etc).
Code:
FORM.fieldnames
will contain duplicate names.
Also, he uses the
Code:
Evaluate()
function, which Macromedia recommends you avoid.

The proper way to code this functionality is to treat the FORM scope as a structure (since, in fact, it is):
Code:
<CFLOOP collection=&quot;#FORM#&quot; item=&quot;whichField&quot;>
   <CFOUTPUT>#whichField# = #FORM[whichField]#</CFOUTPUT><br>
</CFLOOP>
but, again, it's doubtful that would output any form fields that CFDUMP wouldn't.


-Carl
 
thanks for responding. I determined that it was most definitely the form that was the problem.. even sending the variables with &quot;get&quot; i could see that only the first set were sent with the URL. if you can believe how stupid this is i had a stray </form> tag in there so it was sending the elements created by an inner loop and ignoring the outer loop. next time I'll put away the crack pipe before posting.

 
keep in mind that not ALL form elements will return if the value is empty. checkboxes, radio buttons, only the submit button that is presses (if you have more than one submit (I found this weekend if you submit with the ENTER key no submit values are sent, you must click the submit button with the mouse (noted in IE6))) text fields do send an empty string if you leave them blank.

make your form action = &quot;
I've written a series of loops to evaluate your form and url values.

thereptilian120x120.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top