Re: How to create a array with Form Fields?

From: Date: Wed, 06 Sep 2000 18:03:37 +0000
Subject: Re: How to create a array with Form Fields?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-15566@lists.php.net to get a copy of this message
On Wed, 6 Sep 2000, Santhyago Bueno Gallao wrote: > Can i do this? Is this code correct? > > for ($i = 0; $i < 10; $i ++) > { > printf('<input type="text" name="campo[%d]">',$i); > } > > //-------------------------------------------------- > > And get the values: > > for ($j = 0; $j < 10; $j ++) > { > $soma = $soma+$campo[$j]; > } > > Please, help me. You can, and it is correct. Though it'd be easier/faster to use echo instead of printf. Here's your code in a working, self-contained block: <? if( isset($action) ) { for ($j = 0; $j < 10; $j++) $soma += $campo[$j]; echo "Soma is: $soma<br>"; } ?> <form method=get action=<? echo $PHP_SELF ?>> <? for ($i = 0; $i < 10; $i ++) echo '<input type="text" name="campo[' . $i . ']"><br>'; ?> <input type=reset> &nbsp; <input type=submit name=action value="Add"> </form> Matt

« previous php.general (#15566) next »