FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » How to get the POST name of a field in a form that uses a counter
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
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 Go to previous messageGo to previous message
Ben Bacarisse is currently offline  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.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Message Subject
Next Topic: query: how many use PHP for linux scripts
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Sep 18 13:14:35 GMT 2024

Total time taken to generate the page: 0.07187 seconds