Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #13714
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: How to get the POST name of a field in a form that uses a counter |
| Date | 2014-05-15 08:15 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <ll2b4m$qnr$1@dont-email.me> (permalink) |
| References | <XnsA32DA68DB274Farbpenyahoocom@78.46.70.116> |
On 5/14/2014 7:22 PM, Adrienne Boswell wrote:
> 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.
>
> I'm sure the answer to this is pretty simple, but I had a hard enough
> time trying to figure out a subject for this post, let alone knowing how
> to google for it.
>
> TIA for your help. I appreciate it.
>
>
I think you're going about this the wrong way. You should use a two
dimensional array for your value; it will be much easier in the long run.
Your input statement should look like:
<input type="text" name="howmuch[]"... >
Then your $_POST elements would be $_POST['howmuch'][0],
$_POST['howmuch'][1], etc.
You can also then use foreach($_POST['howmuch'] as ...)
to go through the 'howmuch' elements in the $_POST array.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to get the POST name of a field in a form that uses a counter Adrienne Boswell <arbpen@yahoo.com> - 2014-05-14 23:22 +0000
Re: How to get the POST name of a field in a form that uses a counter Christoph Michael Becker <cmbecker69@arcor.de> - 2014-05-15 02:15 +0200
Re: How to get the POST name of a field in a form that uses a counter Denis McMahon <denismfmcmahon@gmail.com> - 2014-05-15 01:01 +0000
Re: How to get the POST name of a field in a form that uses a counter Denis McMahon <denismfmcmahon@gmail.com> - 2014-05-15 01:19 +0000
Re: How to get the POST name of a field in a form that uses a counter The Natural Philosopher <tnp@invalid.invalid> - 2014-05-15 03:29 +0100
Re: How to get the POST name of a field in a form that uses a counter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-05-15 02:55 +0100
Re: How to get the POST name of a field in a form that uses a counter Arno Welzel <usenet@arnowelzel.de> - 2014-05-15 10:22 +0200
Re: How to get the POST name of a field in a form that uses a counter Jerry Stuckle <jstucklex@attglobal.net> - 2014-05-15 08:15 -0400
Re: How to get the POST name of a field in a form that uses a counter Adrienne Boswell <arbpen@yahoo.com> - 2014-05-15 22:45 +0000
csiph-web