Re: How to get the POST name of a field in a form that uses a counter [message #185936 is a reply to message #185931] |
Thu, 15 May 2014 01:55 |
Ben Bacarisse
Messages: 82 Registered: November 2013
Karma:
|
Member |
|
|
Adrienne Boswell <arbpen(at)yahoo(dot)com> writes:
> I need to how to get the POST name of a field in a form that uses a
> counter. The fields are named based on that loop. Below is a small
> snippet of what I am doing:
>
> <?php
>
> $howmuch = array(20, 30, 5, 10, 15);
>
> ?>
> <form method="post">
> <?php
> for($s=0;$s<count($howmuch);++$s)
> {?>
> <input type="text" name="howmuch<?php echo $s; ?>" value="<?php echo
> $_POST[$howmuch ?]$s; ?>">
$_POST['howmuch' . $s];
seems to be what you mean.
> <?php } ?>
> <input type="submit" value="Submit">
> </form>
You can, if it helps, get PHP to make $_POST['howmuch'] be a proper
array rather than having five separate numbered elements in $_POST. You
do this by writing array brackets in the input element's name:
name="howmuch[<?php echo $s ?>]"
Upon submission, $_POST['howmuch'] will then be an array you can index
like this: $_POST['howmuch'][0] and so on. Thus you'd write
value="<?php echo $_POST['howmuch'][$s] ?>"
if you needed to show the value entered.
<snip>
--
Ben.
|
|
|