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

Post form values as array

Status
Not open for further replies.

BigBadDave

Programmer
May 31, 2001
1,069
EU
Hi, How do you post form values as an array? In PHP I would do it like this:

Code:
<?php

for ($i = 0; $i < 5; $i++) {
    echo &quot;<input name='foo[]'>&quot;;
}

?>

Then I could read the posted results back like this:

Code:
<?php

for ($i = 0; $i < count ($_POST[&quot;foo&quot;]); $i++) {
    echo &quot;Result of foo $i is: &quot; . $_POST[&quot;foo&quot;][$i];
}

?>

How do I do this with Cold Fusion Regards
David Byng
bd_logo.gif

davidbyng@hotmail.com
 
I havn't really explained myself, what I mean is:

Code:
<input name='foo[]' value=&quot;one&quot;>
<input name='foo[]' value=&quot;two&quot;>
<input name='foo[]' value=&quot;three&quot;>
<input name='foo[]' value=&quot;four&quot;>
<input name='foo[]' value=&quot;five&quot;>

Then I could read the posted results back like this:

Code:
<?php

for ($i = 0; $i < count ($_POST[&quot;foo&quot;]); $i++) {
    echo &quot;Result of foo $i is: &quot; . $_POST[&quot;foo&quot;][$i];
}

?>

How do I do this with Cold Fusion Regards
David Byng
bd_logo.gif

davidbyng@hotmail.com
 
I'm not sure that you can replicate the array you depict (I'm not even sure it's valid HTML)... but what you can do is simply append a number dynamically to the field name, like:

Code:
<!--- value list would come from whatever source you need.
      this list is just for example purposes --->
<CFSET myValueList = &quot;one,two,three,four,five&quot;>
<CFOUTPUT>
<FORM action=&quot;...&quot; METHOD=&quot;POST&quot;>
  <CFLOOP index=&quot;whichField&quot; from=&quot;1&quot; to=&quot;5&quot;>
    <INPUT name=&quot;foo#whichField#&quot; value=&quot;#ListGetAt(myValueList,whichField)#&quot;>
  </CFLOOP>
  <input type=&quot;submit&quot; name=&quot;submit&quot; id=&quot;submit&quot; />
  </FORM>
</CFOUTPUT>

then your action page can dynamically pull the values like:

Code:
<CFOUTPUT>
<CFLOOP index=&quot;whichField&quot; from=&quot;1&quot; to=&quot;5&quot;>
  Result of foo #whichField# is: #FORM[&quot;foo&quot; & whichField]#<br />
</CFLOOP>
</CFOUTPUT>

Would that do it for you?

Hope it helps,
-Carl
 
Yeah thanks that works, but now how do I loop an SQL update? like this:

Code:
<cfloop index=&quot;i&quot; from=&quot;1&quot; to=&quot;#form.arrTotal#&quot;>
  <cfquery name=&quot;update#i#&quot; datasource=&quot;ema&quot;>
    #PreserveSingleQuotes (sql[i])#
  </cfquery>
</cfloop>

That dosn't work how do I do it? Regards
David Byng
bd_logo.gif

davidbyng@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top