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 #185946 is a reply to message #185931] Thu, 15 May 2014 08:22 Go to previous messageGo to previous message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma:
Senior Member
Am 15.05.2014 01:22, schrieb Adrienne Boswell:

> 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; ?>">
> <?php } ?>
> <input type="submit" value="Submit">
> </form>
>
> Here's where my problem is:
>
> When the user hits submit, I would get something in the post array like:
>
> howmuch0 : 20
> howmuch1 : 30
> howmuch2 : 5
> howmuch3 : 10
> howmuch4 : 15
>
> On a regular form, value="<?php echo $_POST[$howmuch]; ?>" works just
> fine, but since I'm naming the field in a loop, I need to have that, too.
> Using $_POST[$howmuch ?]$s; is not valid.

foreach() should be your friend.



--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
http://fahrradzukunft.de
[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: Sat Nov 09 12:11:31 GMT 2024

Total time taken to generate the page: 0.04078 seconds