How to convert hidden form variables into an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mfk5150
Forum Newbie
Posts: 2
Joined: Mon Nov 25, 2002 6:24 pm
Location: Philadelphia, PA

How to convert hidden form variables into an array

Post 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; ?>">
<? } ?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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[]
mfk5150
Forum Newbie
Posts: 2
Joined: Mon Nov 25, 2002 6:24 pm
Location: Philadelphia, PA

Post by mfk5150 »

thanks. worked perfectly.
Post Reply