Page 1 of 1

How to convert hidden form variables into an array

Posted: Mon Nov 25, 2002 6:24 pm
by mfk5150
I am creating hidden form field variable names using a 'for' loop (example 1) on page1.php and it passes the variables through a form post to page2.php, so that when they are received by page2.php they are defined as $recipient1, $recipient2, etc...

My question, I have potentially 500 variables being sent via hidden form fields with the same naming convention, is there a way to dump the value of $recipient1 into $recipient[1] using a for loop or do i have to assign them individually.

EXAMPLE 1
<? for ($y=0; $y < count($data); $y++) { ?>
<input type="checkbox" name="recipient<? echo $y; ?>" value="<? echo $name; ?>">
<? } ?>

Posted: Mon Nov 25, 2002 7:37 pm
by volka
try

Code: Select all

&lt;html&gt;&lt;body&gt;&lt;form method="POST"&gt;
&lt;?php
for ($i=0; $i!=10;$i++)
	echo '&lt;input type="checkbox" name="chkbox&#1111;]" value="', $i, '" /&gt;',$i,'&lt;br/&gt;';
?&gt;
&lt;input type="submit" /&gt;
&lt;/form&gt;
&lt;fieldset&gt;&lt;legend&gt;posted values&lt;/legend&gt;
	&lt;pre&gt;&lt;?php print_r($_POST) ?&gt;&lt;/pre&gt;
&lt;/fieldset&gt;
&lt;/body&gt;&lt;/html&gt;
notice chkbox[]

Posted: Tue Nov 26, 2002 11:31 am
by mfk5150
thanks. worked perfectly.